iOS

来源:互联网 发布:seo效果检测步骤包括 编辑:程序博客网 时间:2024/06/05 17:24

在一个block中进行了present vc的行为,结果present失败,出现了warning:

Warning: Attempt to present on whose view is not in the window hierarchy!

在多方查找验证之后,发现下边方案可以解决此问题:

将之前present的语句换成下边的语句

UIViewController *mviewController = [UIApplication sharedApplication].keyWindow.rootViewController;                    if (mviewController.presentedViewController) {                        [mviewController.presentedViewController dismissViewControllerAnimated:false completion:^{                            [mviewController presentViewController:nav animated:YES completion:nil];                        }];                    }else {                        [mviewController presentViewController:nav animated:YES completion:nil];                    }

其中的nav时之前创建好的用于present的UINavigationController实例

希望对你有用~

0 0