whose view is not in the window hierarchy
来源:互联网 发布:淘宝上禁止发布商品 编辑:程序博客网 时间:2024/05/21 03:27
在应用中present手势密码界面的时候,报错:
Attempt to present <ViewController2: 0x7fab01e1c430> on <ViewController: 0x7fab01d30a00> whose view is not in the window hierarchy!
具体类似这样:我先在一个原始界面(假设为VC)present出来VC1(这个过程是没问题的),然后过一定时间后,又从VC中present出来VC2,这个时候报错了。以上这个报错是什么意思呢?就是负责present的VC的view界面不在当前最上面的window中(也就是不可见的),所以不能执行present功能。
网上还有很多关于这个问题的文章,大部分的解决方案是这样的:
将present方法放到viewDidAppear方法里面去执行。我分析用此种解决方案的问题出现的原因是在view还没有显示出来之前,就调用了
[presentViewController:animated: completion:]方法,所以才报以上错误。而我遇到这个报错是因为在VC消失之后调用present方法,这也是不正确的,你只有在当前window中的VC界面中才能调用此方法。
我的解决方案是这样的:找到应用程序中最顶层的那个ViewController,然后再调用present方法,这样就ok了。
如何在window中找到应用程序中最顶层的那个ViewController,代码如下
+ (UIViewController *)topViewController
{
return [selftopViewController:[UIApplicationsharedApplication].keyWindow.rootViewController];
}
+ (UIViewController *)topViewController:(UIViewController *)rootViewController
{
if (rootViewController.presentedViewController ==nil) {
return rootViewController;
}
if ([rootViewController.presentedViewControllerisMemberOfClass:[UINavigationControllerclass]])
{
UINavigationController *navigationController = (UINavigationController *)rootViewController.presentedViewController;
UIViewController *lastViewController = [[navigationControllerviewControllers] lastObject];
return [selftopViewController:lastViewController];
}
UIViewController *presentedViewController = (UIViewController *)rootViewController.presentedViewController;
return [selftopViewController:presentedViewController];
}
直接调用第一个+方法就ok了,得到topVC,然后就可以呈现手势密码界面了
[topVC presentViewController:gestureVC animated:YES completion:^{}];
如果有不对的地方,欢迎指正!
- whose view is not in the window hierarchy!
- whose view is not in the window hierarchy!
- whose view is not in the window hierarchy
- whose view is not in the window hierarchy
- whose view is not in the window hierarchy
- whose view is not in the window hierarchy
- whose view is not in the window hierarchy!
- whose view is not in the window hierarchy!
- window模态导航控制器出现的问题 "whose view is not in the window hierarchy!"
- 对Warning: Attempt to present on whose view is not in the window hierarchy!的解决方案
- Warning: Attempt to present A on B whose view is not in the window hierarchy!
- 对Warning: Attempt to present on whose view is not in the window hierarchy!的解决方案
- 对Warning: Attempt to present on whose view is not in the window hierarchy!的解决方案
- Warning: Attempt to present * on * whose view is not in the window hierarchy!
- Warning: Attempt to present xx on yy whose view is not in the window hierarchy!
- Warning: Attempt to present A on B whose view is not in the window hierarchy!
- Attempt to present on whose view is not in the window hierarchy!
- ios开发异常:whose view is not in the window hierarchy! (20
- vector容器与iterator迭代器
- Linux查看物理CPU个数、核数、逻辑CPU个数
- R语言中单变量的各种图形的绘制
- 设置Tabber 的提示通知
- HDU 4513 吉哥系列故事――完美队形II(Manacher)
- whose view is not in the window hierarchy
- 理解JavaScript中的事件处理
- ViewStub用法
- UILable 的自使用 iOS
- chmod 600 .ssh/authorized_keys修改权限
- Java 入门 之 Socket 服务器通信
- MSF - searchengine_subdomains_collector
- Android安全攻防战,反编译与混淆技术完全解析(上)
- WebRTC 学习笔记(2)--libjingle 部分 (P2P传输)