美文网首页iOS快速开发总结
A页面 present B页面 , B页面 dismiss 后

A页面 present B页面 , B页面 dismiss 后

作者: 键盘上的演绎者 | 来源:发表于2017-12-20 09:14 被阅读24次

    编译器给出的提示如下:
    Warning: Attempt to present <UINavigationController: 0x7fdd22262800> on <UITabBarController: 0x7fdd21c33a60> whose view is not in the window hierarchy!

    解决办法:

        ReleaseDiscussVC *releaseVC = [ReleaseDiscussVC new];
        UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:releaseVC];
    
        UIViewController *rootVC = [UIApplication sharedApplication].keyWindow.rootViewController;
        /* rootVC.presentedViewController只有present才有值,push的时候为nil
         */
        
        //防止重复弹
        if ([rootVC.presentedViewController isKindOfClass:[UINavigationController class]]) {
            UINavigationController *navigation = (id)rootVC.presentedViewController;
            if ([navigation.topViewController isKindOfClass:[ReleaseDiscussVC class]]) {
                return;
            }
        }
        if (rootVC.presentedViewController) {
            //要先dismiss结束后才能重新present否则会出现
            //Warning: Attempt to present <UINavigationController: 0x7fdd22262800> on <UITabBarController: 0x7fdd21c33a60> whose view is not in the window hierarchy!
            //就会present不出来登录页面
            [rootVC.presentedViewController dismissViewControllerAnimated:false completion:^{
                [rootVC presentViewController:nav animated:true completion:nil];
            }];
        }else {
            [rootVC presentViewController:nav animated:true completion:nil];
        }
    

    相关文章

      网友评论

        本文标题:A页面 present B页面 , B页面 dismiss 后

        本文链接:https://www.haomeiwen.com/subject/tixiwxtx.html