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

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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 hierarchy!

原因:页面跳转必须在viewDidLoad和viewDidAppear之后才能进行。

解决办法:必须确保页面跳转要在view load完毕之后进行。

第一种:通过延时来等待view Load执行结束,但是这个方法在时间上不好把握

第二种:在viewDidLoad里用

 [selfperformSelectorOnMainThread:@selector(login)withObject:nilwaitUntilDone:NO];

把页面跳转的代码写进函数里,然后将 waitUntilDone 设为NO

以上是关于Warning: Attempt to present on whose view is not in the window hierarchy!的主要内容,如果未能解决你的问题,请参考以下文章

[!] Attempt to read non existent folder `***********`

***-[__NSPlaceholderDictionary initWithObjects:forKeys:count:]: attempt to insert nil object from ob

attempt to create delete event with null entity

Opening socket connection to server :2181. Will not attempt to authenticate using SASL (unknown err

Java反射报错“Attempt to get int field “i“ with illegal data type conversion to short“

Zookeeper报错Will not attempt to authenticate using SASL解决办法