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

在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
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值