我正在 Xcode 中使用 Swift 和 Storyboard 开发一个应用程序。2 个视图控制器彼此重叠显示,我想通过按一个按钮来关闭它们。我已经在 StackOverflow 上搜索了答案,我找到了self.navigationController?.popToRootViewController(animated: true)
,但没有用。你对为什么这行不通有什么想法吗?
在这种情况下起作用的只是使用另一行代码。我不知道有什么不同,但它以某种方式起作用:
self.view.window!.rootViewController?.dismiss(animated: true, completion: nil)
检查您的 NavigationController 是否为零 ...
if let nav = self.navigationController {
nav.popToRootViewController(animated: true)
} else {
print("nav is nil")
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句