在一个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实例
希望对你有用~
本文介绍了解决iOS开发中PresentViewController导致的警告问题的方法。通过检查当前ViewController的状态,并使用适当的方式进行展示或关闭模态视图控制器,避免了不在窗口层级的警告。
1万+

被折叠的 条评论
为什么被折叠?



