iOS开发异常warning:***whose view is not in the window hierarchy!

来源:互联网 发布:python下载matplotlib 编辑:程序博客网 时间:2024/05/21 01:57

在storyboard中,目前碰到几种情况:
1、由controller A跳转到controller B的时候然后报Warning: Attempt to present on whose view is not in the window hierarchy!

2、在controller A中present一个自定义controller B,或者类似UIActivityViewController、UIAlertViewController时,报Warning: Attempt to present controller B on controller A whose view is not in the window hierarchy!

参考:
http://stackoverflow.com/questions/11862883/whose-view-is-not-in-the-window-hierarchy
从这里了解到问题应该是viewDidLoad:与viewDidAppear:的区分了;

确实,上面两个问题的场景都是 将presentVC写在viewDidLoad中了;

那么依据stackoverflow中说法:
“the view controller’s view is not in the window hierarchy at the point that it has been loaded (when the viewDidLoad message is sent), but it is in the window hierarchy after it has been presented (when the viewDidAppear: message is sent).”

如果我翻译的话,就是说正规是在viewDidAppear之后,view才in the window hierarchy,这时presentViewController:才有效

果然,将上面的1、2中的代码移动到viewDidAppear之后, —- AC!

1 0
原创粉丝点击