【发布时间】:2020-11-10 18:45:57
【问题描述】:
我正在开发一个在 Xcode 中使用 Swift 和 Storyboard 的应用程序。 2 个视图控制器相互叠加,我想通过按下按钮来关闭它们。我已经在 StackOverflow 上搜索了这里的答案,我找到了self.navigationController?.popToRootViewController(animated: true),但它没有用。您对为什么这行不通有什么想法吗?
解决方案:
在这种情况下起作用的只是使用另一行代码。我不知道有什么不同,但它以某种方式起作用:
self.view.window!.rootViewController?.dismiss(animated: true, completion: nil)
【问题讨论】:
-
你确定 self.navigationController 不是 nil 吗?
-
如何检查?
-
@FrederikBrammer 使用调试器?
标签: ios swift xcode uiviewcontroller uinavigationcontroller