iOS快速开发总结

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

2017-12-20  本文已影响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];
    }
上一篇下一篇

猜你喜欢

热点阅读