博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
iOS 开发中 Whose view is not in the window hierarchy 错误的解决办法
阅读量:4297 次
发布时间:2019-05-27

本文共 1086 字,大约阅读时间需要 3 分钟。

在 iOS 开发当中经常碰到 whose view is not in the window hierarchy 的错误,该错误简单的说,是由于 "ViewController" 还没有被加载,就调用该 ViewController 或者 ViewController 内的方法时,就会报这个错误。
 
在不同地方调用 ViewController,解决的方法也不太一样。
 
1. 在 一个 ViewController 里面调用另外一个 ViewController 是出现这个错误: 
该错误一般是由于在 viewDidLoad 里面调用引起的,解决办法是转移到 viewDidAppear 方法里面
 
2. 在 AppDelegate.m 中调用遇到这个错误 
 
解决办法1:
 
UIViewController *topRootViewController = [UIApplication sharedApplication].keyWindow.rootViewController;
while (topRootViewController.presentedViewController)
 {
    topRootViewController = topRootViewController.presentedViewController;
 }
 
//[topRootViewController presentViewController:yourController animated:YES completion:nil];
//or
[topRootViewController myMethod];
 
解决办法2:
 
 UIStoryboard *mainstoryboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
    LoginViewController* loginViewController = [mainstoryboard instantiateViewControllerWithIdentifier:@"LoginViewController"];
    [self.window makeKeyAndVisible];
//[LoginViewController presentViewController:yourController animated:YES completion:nil];
//or
[LoginViewController myMethod];

转载地址:http://fkdws.baihongyu.com/

你可能感兴趣的文章
VNPY2.0火币期货交易接口配置使用
查看>>
win10和ubuntu18双系统时间同步(20190604亲测可行)
查看>>
重启小狼毫输入法,rime输入法重启
查看>>
命令行或终端ImportError:No module named(pycharm运行没问题)
查看>>
量化策略回测01双均线
查看>>
量化策略回测ATRRSI
查看>>
量化干货:量化交易系统设计的六大细节
查看>>
量化策略回测tdma
查看>>
量化策略回测TRIXKDJ
查看>>
量化策略回测唐安奇通道
查看>>
CTA策略如何过滤部分震荡行情?
查看>>
量化策略回测DualThrust
查看>>
量化策略回测BoolC
查看>>
量化策略回测DCCV2
查看>>
mongodb查询优化
查看>>
五步git操作搞定Github中fork的项目与原作者同步
查看>>
git 删除远程分支
查看>>
删远端分支报错remote refs do not exist或git: refusing to delete the current branch解决方法
查看>>
python multiprocessing遇到Can’t pickle instancemethod问题
查看>>
APP真机测试及发布
查看>>