A页面 present B页面 , B页面 dismiss 后 present C页面 不出来的解决

编译器给出的提示如下:
Warning: Attempt to present on 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  on  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 后 present C页面 不出来的解决)