iOS-OC PresentedViewController 与 PresentingViewController使用技巧

转载自: https://www.jianshu.com/p/2bec31eb4f96

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

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值