对Warning: Attempt to present on whose view is not in the window hierarchy!的解决方案
来源:互联网 发布:开淘宝店铺经验 编辑:程序博客网 时间:2024/05/16 14:22
- (void)presentViewController:(UIViewController *)viewControllerToPresent animated: (BOOL)flag completion:(void (^)(void))completion;当然也可以用导航push。
可是昨天就遇到了题目中的warning,在stackoverflow找到了答案:点击打开链接
大意就是页面跳转必须在viewDidLoad和viewDidAppear之后才能进行。解决的办法就是确保页面跳转要在view load完毕之后进行。大神说可以通过设置延时来实现,通过实验我觉得这个不好控制,到底需要延时多少呢》
后来换了一个方案,在viewDidLoad里用
[selfperformSelectorOnMainThread:@selector(login)withObject:nilwaitUntilDone:NO];
把页面跳转的代码写进函数里,然后将 waitUntilDone 设为NO,就是viewDidLoad直接返回不用等login执行。这样就可以确保login里的页面跳转是在viewDidLoad之后执行。
另外,我还遇到下面这个情况:A页面跳转到B,在B里又封装了一个页面跳转(至C)。
也就是在前面的login函数里,从A跳转至B时会传入token、secret等用来获取用户授权的数据,然后在B里再调各大公司封装好的授权页面(如百度网盘、新浪微博)。
一开始我的login实现如下:
-(void)login
{
loginViewController *loginVC=[[loginViewControlleralloc]init];
loginVC.delegate=self;
[self presentViewController:loginVCanimated:NOcompletion:nil];
[loginVC auth:BAIDU_API_KEY secret:nil disk:BAIDU];//这个函数里有跳转至授权页面
}
这同样会出现上面的问题,解决的办法就是把最后一行的函数放在completion的block里。
-(void)login
{
loginViewController *loginVC=[[loginViewController alloc]init];
loginVC.delegate=self;
[self presentViewController:loginVCanimated:NO completion:^{[loginVCauth:BAIDU_API_KEY secret:nildisk:BAIDU];}];
}
因为:The completion handler, if provided, will be invoked after the presented controllers viewDidAppear: callback is invoked.
- 对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 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 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 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!
- Warning: Attempt to present A on B whose view is not in the window hierarchy!
- xcode编译Warning: Attempt to present xx on yy whose view is not in the window hierarchy!
- iOS - 报错 Warning: Attempt to present <xx: xx> on <xx: xx> whose view is not in the window hierarchy!
- Warning: Attempt to present ControllerA and ControllerB whose view is not in the window hierarchy!
- Attempt to present on whose view is not in the window hierarchy!
- Attempt to present on whose view is not in the window hierarchy!
- iOS 简单的实现手机号正误的判断(Warning: Attempt to present... whose view is not in the window hierarchy!
- 处理iOS报错: Warning “attempt to present ViewController whose view is not in the window hierarchy”
- Attempt to present VC whose view is not in the window hierarchy 解决
- C++ STL入门教程(7)——multimap(一对多索引),multiset(多元集合)的使用(附完整程序代码)
- sql语句判断两个时间段是否有交集
- poj1948 Triangular Pastures
- Maxiee的Vim入门日记(5)——用Vim看aMule代码
- 05.net网站开发(设计):2.MVC控制器与视图的简单收发数据
- 对Warning: Attempt to present on whose view is not in the window hierarchy!的解决方案
- openfire 插件开发 打包
- OPENCV C++接口的复制roi数据。
- 客户端网页编程:CSS页面布局基础
- poj 2031 Building a Space Station
- php 判断上传文件类型 $_files[]['type']值大全
- Session 与Cookie
- poj 2079 Triangle(旋转卡壳)
- How To Check and Use Serial Ports Under Linux