iOS-OC PresentedViewController 與 PresentingViewController使用技巧

PresentedViewController 與 PresentingViewController區(qū)別

假設(shè)從A控制器通過present的方式跳轉(zhuǎn)到了B控制器,那么 A.presentedViewController 就是B控制器;B.presentingViewController 就是A控制器。

使用場(chǎng)景一:presentingViewController

從A跳轉(zhuǎn)到B,從B跳轉(zhuǎn)到C,從C跳轉(zhuǎn)到D,如何由D直接返回到A呢?可以通過 presentingViewController 一直找到A控制器,然后調(diào)用A控制器的 dismissViewControllerAnimated 方法。

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

使用場(chǎng)景二:PresentedViewController

在當(dāng)前ViewController連續(xù)調(diào)用 [self presentViewController:vc animated:YES completion:^{}];,連續(xù)跳轉(zhuǎn)

UIViewController *topRootViewController = self.window.rootViewController;
            
 // 在這里加一個(gè)這個(gè)樣式的循環(huán)
 while (topRootViewController.presentedViewController) {
       // 這里固定寫法
      topRootViewController = topRootViewController.presentedViewController;
      }
            
CTNavigationController *naVc = [[CTNavigationController alloc]initWithRootViewController:receiveOrderVC];
            // 然后再進(jìn)行present操作
[topRootViewController presentViewController:naVc animated:YES completion:nil];
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

推薦閱讀更多精彩內(nèi)容