对Warning: Attempt to present XXX on XXX whose view is not in the window hierarchy!的解决方案

下面是我找到的最靠谱的答案了。尝试后问题果然解决了。分享给大家。http://blog.csdn.net/sbvfhp/article/details/19826221

当我想从一个VC跳转到另一个VC的时候,

一般会用- (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之后执行。

时间: 2024-10-29 19:07:51

对Warning: Attempt to present XXX on XXX whose view is not in the window hierarchy!的解决方案的相关文章

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

UIViewController 显示的主页面 添加了一个scrollView UICollectionViewController 自带collectionView UITableViewController A自带 tableView UITableViewController  B 被present的界面 把collectionView,tableView 添加到scrollView上以显示滑动效果 问题,从UICollectionViewController 的cell选中present

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

当我想从一个VC跳转到另一个VC的时候,一般会用 - (void)presentViewController:(UIViewController *)viewControllerToPresent animated: (BOOL)flag completion:(void (^)(void))completion;当然也可以用导航push. 有时会遇到了此类警告:Warning: Attempt to present on whose view is not in the window hier

Warning: Attempt to present * on * which is already presenting *

Warning: Attempt to present (要被presented的控制器)  on (哪个控制器来presenting) which is already presenting (已经被presenting的控制器) self: 是被presented出来的控制器, self.presentingViewController: 看看是谁把self给presenting出来 RPLog(@"%@ - %@", self.presentingViewController,

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

在开发的时候,有时候会遇到 1.ios attempt to present whose view is not in the window hierarchy 2.Warning: Attempt to present on whose view is not in the window hierarchy! 等等这样类似的提示,只要里面提示有 window hierarchy,都是view hierarchy的理解不到位导致的. 上面的问题都是在一个controller的view还没加到wi

Warning: Attempt to present <UIAlertController: 0x7fb6ab704950> on <UIViewController: 0x7fb6ab51c810> whose view is not in the window hierarchy!

对于在UIView上,是不能跳转的,所以我们通常要借助UIViewController,但经常会出现UIViewController没被加载的情况.这时就会报这个错. 解决方法: viewCon = (UIApplication.shared.keyWindow?.rootViewController)!  self.viewCon.present(alertView, animated: true, completion: nil); 希望后面的童鞋不要掉坑里了哦!!!!

iOS8 iPad Warning: Attempt to present <UIImagePickerController:xxxx > on xxxx which is already presenting (null)

解决方法: /* I think this is because in iOS 8, alert views and action sheets are actually presented view controllers (UIAlertController). So, if you're presenting a new view controller in response to an action from the UIAlertView, it's being presented w

Attempt to present <vc> on <vc> which is already presenting <vc>/(null)

在给 tableViewCell 添加长按手势弹出一个 popViewController 的时候,遇到的这个变态问题: Warning: Attempt to present <UINavigationController: 0x15f259c00>  on <RepoDetailViewController: 0x160271400> which is already presenting (null) 我的solution : 不使用手势去运行此方法.换用了button的ad

Error Domain=ASIHTTPRequestErrorDomain Code=8 &quot;Failed to move file from&quot;xxx/xxx&quot;to&quot;xxx/xxx&quot;

今天真的好高兴呀 我解决了一个折磨了我一周的问题,真的是激动地要哭出来了,为了这个问题,我嘴也烂了,头发抓了一地啊.虽然解决方法,最后还是展现出了“百度”的伟大,但是我还是很开心,在这里我展示一下我的战果 问题的表面就是在2G下下载zip包失败,不是每次都失败,而是只要我离开当前页面再次进入当前页面就会失败(进入requestFail),如果只是离开不进入,那么一起正常. 多么诡异呀,起初我也想通过看看进入页面后是不是进行了什么卑鄙的操作,而导致ASI罢工,可是最后我放弃了,因为任何有关ASI的

sql数据库删除表的外键约束(INSERT 语句与 FOREIGN KEY 约束&quot;XXX&quot;冲突。该冲突发生于数据库&quot;XXX&quot;,表&quot;XXX&quot;, column &#39;XXX)

使用如下SQL语句查询出表中外键约束名称: 1 select name 2 from sys.foreign_key_columns f join sys.objects o on f.constraint_object_id=o.object_id 3 where f.parent_object_id=object_id('表名') 执行如下SQL语句删除即可. 1 alter table 表名 drop constraint 外键约束名 sql数据库删除表的外键约束(INSERT 语句与 F