Wi-Fi参考iOS

iOS-OC PresentedViewController 与

2018-02-28  本文已影响665人  Simple_Code

PresentedViewController 与 PresentingViewController区别

假设从A控制器通过present的方式跳转到了B控制器,那么 A.presentedViewController 就是B控制器;B.presentingViewController 就是A控制器。

使用场景一:presentingViewController

从A跳转到B,从B跳转到C,从C跳转到D,如何由D直接返回到A呢?可以通过 presentingViewController 一直找到A控制器,然后调用A控制器的 dismissViewControllerAnimated 方法。

UIViewController *controller = self;
while(controller.presentingViewController){
   controller = controller.presentingViewController;
}
[controller dismissViewControllerAnimated:YES completion:nil];

使用场景二:PresentedViewController

在当前ViewController连续调用 [self presentViewController:vc animated:YES completion:^{}];,连续跳转

UIViewController *topRootViewController = self.window.rootViewController;
            
 // 在这里加一个这个样式的循环
 while (topRootViewController.presentedViewController) {
       // 这里固定写法
      topRootViewController = topRootViewController.presentedViewController;
      }
            
CTNavigationController *naVc = [[CTNavigationController alloc]initWithRootViewController:receiveOrderVC];
            // 然后再进行present操作
[topRootViewController presentViewController:naVc animated:YES completion:nil];
上一篇下一篇

猜你喜欢

热点阅读