OGeek|极客世界-中国程序员成长平台

标题: ios - UIStoryboard 引用和 Root View Controller [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-11 17:26
标题: ios - UIStoryboard 引用和 Root View Controller

我有一个“主” Storyboard,在这个 Storyboard内我有一个 Storyboard引用实体,它链接到另一个 Storyboard“登录”。我注意到,当我尝试使用以下内容访问当前屏幕上的 View 时:

[[[[UIApplication sharedApplication]delegate]window]rootViewController]

它返回了“主” Storyboard 上的 View ,但如果我尝试在此 View 上推送 UIAlertController,我会收到以下错误:

Warning: Attempt to present <UIAlertController: 0x1839a000> on <ViewController: 0x17633ad0> whose view is not in the window hierarchy!

是否有原因我不能将此 View 推到顶部,如果不是,我如何从“登录” Storyboard 中获取当前显示的实际 uiviewcontroller?



Best Answer-推荐答案


如果您从 viewDidload 呈现 UIAlertController 那么它可能会发生这样的情况,因为当时正在加载 View 时,它在完全加载之前不在 Windows 层次结构中。

第二件事你必须在最顶部的 View Controller 上显示 UIAlertController,例如,

 [self presentViewController......];

不在 Windows rootViewController 上。所以,这取决于你如何做到这一点。

关于ios - UIStoryboard 引用和 Root View Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39327574/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://ogeek.cn/) Powered by Discuz! X3.4