关闭

presentViewController 的疑问

63人阅读 评论(0) 收藏 举报

刚才用presentViewController去切换页面  出现了如下的错误报告


Warning: Attempt to present <UINavigationController: 0x6e8ade0> on <LoginViewController: 0x6b3ef90> whose view is not in the window hierarchy!


用万能的百度搜了下  


如下是解决方法   亲测可以,记录一下


- (UIViewController*)topViewController

{

    return [self topViewControllerWithRootViewController:[UIApplication sharedApplication].keyWindow.rootViewController];

}


- (UIViewController*)topViewControllerWithRootViewController:(UIViewController*)rootViewController

{

    if ([rootViewController isKindOfClass:[UITabBarController class]]) {

        UITabBarController *tabBarController = (UITabBarController *)rootViewController;

        return [self topViewControllerWithRootViewController:tabBarController.selectedViewController];

    } else if ([rootViewController isKindOfClass:[UINavigationController class]]) {

        UINavigationController* navigationController = (UINavigationController*)rootViewController;

        return [self topViewControllerWithRootViewController:navigationController.visibleViewController];

    } else if (rootViewController.presentedViewController) {

        UIViewController* presentedViewController = rootViewController.presentedViewController;

        return [self topViewControllerWithRootViewController:presentedViewController];

    } else {

        return rootViewController;

    }

}



、、这样进行跳转就可以了

[[self topViewController] presentViewController:nav animated:YES completion:nil];


0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:4671次
    • 积分:336
    • 等级:
    • 排名:千里之外
    • 原创:29篇
    • 转载:12篇
    • 译文:0篇
    • 评论:0条