How to fix the warning: view is not in the window hierarchy

别来无恙 提交于 2019-12-31 07:53:05

问题


I'm using the standard setup procedure for Mobclix in an iOS app and I'm calling the requestAndDisplayAdFromViewController: method from within viewWillAppear:

    - (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];

    [fullScreenAdViewController requestAndDisplayAdFromViewController:self];

}

here's the warning I'm getting:

Warning: Attempt to present <MobclixFullScreenAdViewController: 0x14f2c0> on <EditGameViewController: 0x1838d0> whose view is not in the window hierarchy!

I hope that's enough to go on. thanks for any help.


回答1:


You're calling it from viewWillAppear - at this point, the view is not necessarily in the hierarchy yet (it WILL appear, doesn't mean it has appeared yet). Try calling it from viewDidAppear, which is called when the view is confirmed to be in the hierarchy.




回答2:


Try to move your code [fullScreenAdViewController requestAndDisplayAdFromViewController:self]; to viewDidAppear.




回答3:


You can also try to display the view in the viewDidLoad method.




回答4:


You should try moving this code to viewDidAppear.

From the Apple documentation on viewWillAppear:

This method is called before the receiver’s view is about to be added to a view hierarchy


来源:https://stackoverflow.com/questions/15659526/how-to-fix-the-warning-view-is-not-in-the-window-hierarchy

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!