这里有三个控制器,AViewController
,BViewController
,CViewController
,
第一步:AViewController
呈现给BViewController
;
BViewController *BVC = [[BViewController alloc]init];
[self presentViewController:BVC animated:YES completion:nil];
第二步:BViewController
推送到CViewController
;
CViewController *CVC = [[CViewController alloc]init];
UINavigationController *nav = [[UINavigationController alloc]initWithRootViewController:CVC];
[self.navigationController pushViewController:nav animated:YES];
现在,如果我想从CViewController
返回AViewController
,我应该编写什么代码?
答案 0 :(得分:1)
只需使用此代码:
self.dismissViewControllerAnimated(true, completion: nil)
解除C ViewController,因为C ViewController现在位于导航堆栈上。一个包含B ViewController的导航控制器。 B ViewController push C ViewController,因此C仍在导航控制器中。
你可以在这里查看我的项目:
答案 1 :(得分:1)
你应该像这样展示BViewController
:
BViewController *BVC = [[BViewController alloc]init];
UINavigationController *nav = [[UINavigationController alloc]initWithRootViewController:BVC];
//Setting For Transparent
nav.providesPresentationContextTransitionStyle = YES;
nav.definesPresentationContext = YES;
nav.modalPresentationStyle = UIModalPresentationOverCurrentContext;
[self presentViewController:nav animated:YES completion:nil];
并在BViewController中实现:
- (void)viewWillDisappear:(BOOL)animated {
[self.navigationController setNavigationBarHidden:YES];
}
- (void)viewWillDisappear:(BOOL)animated{
[self.navigationController setNavigationBarHidden:NO];
}
你可以推送到CViewController
:
CViewController *CVC = [[CViewController alloc]init];
[self.navigationController pushViewController:CVC animated:YES];
当你想要回到A.简单地在C中调用它:
[self dismissViewControllerAnimated:YES completion:nil];