iOS - 关于存在和推送控制器的一些问题

时间:2016-02-24 02:48:54

标签: ios pushviewcontroller presentviewcontroller

这里有三个控制器,AViewControllerBViewControllerCViewController, 第一步: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,我应该编写什么代码?

2 个答案:

答案 0 :(得分:1)

只需使用此代码:

self.dismissViewControllerAnimated(true, completion: nil)

解除C ViewController,因为C ViewController现在位于导航堆栈上。一个包含B ViewController的导航控制器。 B ViewController push C ViewController,因此C仍在导航控制器中。

你可以在这里查看我的项目:

https://github.com/khuong291/TestTransition

enter image description here

答案 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];