【发布时间】:2020-07-25 06:36:46
【问题描述】:
我已经看到了类似的问题,但无法找到合适的答案。我现在显示一个视图,我想在单击按钮时从该视图移至根视图控制器。 self.navigationController?.popToRootViewController(animated: true) 不工作。
也试过下面的代码,但它不适合我。
UIApplication.shared.keyWindow?.rootViewController?.dismiss(animated: true, completion: nil)
和
if let appDelegate = UIApplication.shared.delegate as? AppDelegate {
appDelegate.window?.rootViewController?.dismiss(animated: true, completion: nil)
(appDelegate.window?.rootViewController as? UINavigationController)?.popToRootViewController(animated: true)
}
【问题讨论】:
-
你确定 self.navigationController 不是 nil 吗?
-
self.navigationController 为零。
-
那不好,你得阅读一些关于如何使用 NavigationController 的文章或文档。