在我的项目中,我们有三个窗口A,B和C。我想从A推入视图B,而我想从B呈现视图C。
我的代码:
ViewController A:
ViewControllerB *vcB = [[viewControllerB alloc]
initWithNibName:@"ViewControllerB" bundle:nil];
[[self navigationController] pushViewController:vcB animated:YES];
查看控制器B:
ViewControllerC *vcC = [[ViewControllerC alloc]
initWithNibName:@"ViewControllerC" bundle:nil];
[self presentViewController:vcC animated: true completion: nil];
到目前为止,一切都还可以,但是当我使用以下命令关闭最后一个视图控制器时:
[[self presentingViewController] dismissViewControllerAnimated:NO completion:nil];
该应用程序返回到第一个视图控制器(vcA),而不是第二个(vcB)
我究竟做错了什么?
谢谢你们。
最佳答案
您可能正在做其他您没有告诉我们的事情...
这按预期工作:
用MyFirstViewController.m
- (IBAction)pushTapped:(id)sender {
MyPushedViewController *vc = [[MyPushedViewController alloc] initWithNibName:@"MyPushedViewController" bundle:nil];
[self.navigationController pushViewController:vc animated:YES];
}
用
MyPushedViewController.m
- (IBAction)presentTapped:(id)sender {
MyPresentedViewController *vc = [[MyPresentedViewController alloc] initWithNibName:@"MyPresentedViewController" bundle:nil];
[self presentViewController:vc animated:YES completion:nil];
}
用
MyPresentedViewController.m
- (IBAction)dismissTapped:(id)sender {
[self dismissViewControllerAnimated:NO completion:nil];
}
点击
MyPresentedViewController
中的“dismiss”按钮可关闭显示的视图控制器(您的vcC
),而让我留在MyPushedViewController
(您的vcB
)... 而不是MyFirstViewController
(您的vcA
)上的。关于ios - PresentViewController关闭不会返回到以前的viewController,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/48174307/