这是我使用的代码。
在视图控制器 A 中:
- (void)viewDidLoad
{
[super viewDidLoad];
UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[button setFrame:CGRectMake(50, 50, 70, 40)];
[button setTitle:@"Next View" forState:UIControlStateNormal];
[button addTarget:self action:@selector(nextView) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:button];
}
-(void) nextView
{
SecondviewController *secondView = [[SecondviewController alloc] init];
[self.view addSubview:secondView.view];
}
在视图控制器 B 中:
- (void)viewDidLoad
{
[super viewDidLoad];
UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[button setFrame:CGRectMake(50, 50, 70, 40)];
[button setTitle:@"Previous View" forState:UIControlStateNormal];
[button addTarget:self action:@selector(previousView) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:button];
}
-(void) previousView
{
[self.view removeFromSuperview];
}
问题:当我单击视图控制器 B 中的按钮时,它没有切换回视图控制器 A...