获取当前正在显示的任意页面(包括AlertView),然后present到新控制器。

iOS开发中,如果需要在任意一个页面中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];
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容