在要跳转至下一个ViewController
处,创建一个NavigationController
,并将下一个VC
作为它的根VC
,然后显示NavigationController
(NavigationController
中只有一个VC
,所以也就是显示下一个VC
):
NextViewController *vc = [[NextNViewController alloc] init];
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:vc];
[self presentViewController:navigationController animated:YES completion:^{
}];
接着,在NextViewController
添加返回按钮,并返回父视图:
- (void)viewWillAppear:(BOOL)animated {
UIBarButtonItem *backItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(goBack)];
[self.navigationItem setLeftBarButtonItem:backItem];
}
- (void)goBack {
[self.navigationController dismissViewControllerAnimated:YES completion:^{
}];
}