ios - 当我尝试呈现 View 时收到此警告 "attempt to present ViewController whose view is not in the window hierarchy"

标签 ios swift warnings modalviewcontroller

我的 View 层次结构如下图所示:enter image description here

我的问题是我想在单击 VC3 上的任何按钮时显示 VC1。这是我的代码

let storyboard = UIStoryboard(name: "Main", bundle: nil)
let vc = storyboard.instantiateViewControllerWithIdentifier("registerNavigation")
self.presentViewController(vc, animated: false, completion: nil)

但我收到此警告“警告:尝试显示其 View 不在窗口层次结构中的 ViewController”,但没有任何反应。请告诉我,我做错了什么?

最佳答案

如果您想从 VC3 显示 VC1,则无需再次显示它,因为它已经加载到导航堆栈中。您只需要从导航堆栈中dismiss or pop VC3 和VC2。如果您已提交它,则将其关闭;如果您已将其推送,则将其弹出。

您的警告的含义:您正在尝试呈现导航 Controller 1 的 View 层次结构中的内容,但不在导航 Controller 2 的 View 层次结构中。!!

希望这会有所帮助:)

关于ios - 当我尝试呈现 View 时收到此警告 "attempt to present ViewController whose view is not in the window hierarchy",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37384831/

相关文章:

ios - 从委托(delegate)返回元组(可选类型的值未展开)

clang - 如何禁用 [-Werror,-Wpointer-bool-conversion]

php - "Notice: Undefined variable"、 "Notice: Undefined index"、 "Warning: Undefined array key"和 "Notice: Undefined offset"使用 PHP

ios - 在 swift 4 IOS 应用程序中手动添加和引用控件

ios - 在文本字段中显示之前是否可以修改自动填充字符串?

iphone - 有没有办法在没有互联网连接的情况下将多个 iPad(客户端应用程序)连接到中央 iPad(服务器应用程序)?

Swift - 如何在函数 LocationManager() 之外获取纬度和经度值

ios - ASIHTTPRequest 错误域代码 1

swift - 在 Swift 4 中将视频旋转 90 度

c - 如何在 C 中初始化 Const 结构 - 以避免 QAC 警告