iOS開發(fā)中,如果需要在任意一個頁面中present一個controller時,因為有可能當前正在顯示的頁面彈出了alertview或者已經present了一個頁面,導致present到新頁面失效,這時我們可以這樣做:
- (UIViewController *)getPresentedViewController
{
UIViewController *appRootVC = [UIApplication sharedApplication].keyWindow.rootViewController;
UIViewController *topVC = appRootVC;
if (topVC.presentedViewController) {
topVC = topVC.presentedViewController;
}
return topVC;
}
如果當前沒有alertview或者present頁面,那將獲取到rootViewController根控制器,用根控制器去present跳轉,否則將獲取到當前正在present的頁面,用此頁面去跳轉。
[[self getPresentedViewController] presentViewController:_callController animated:NO completion:nil];