【发布时间】:2020-05-14 17:00:42
【问题描述】:
我想关闭所有中间子视图控制器并显示根视图控制器。
以下代码有效:
self.view.window?.rootViewController?.dismiss(animated: true, completion: nil)
但是,我可以短暂地看到中间视图控制器在动画消失到根视图控制器之前闪烁。无论如何,它只是直接动画到根视图控制器?
【问题讨论】:
-
刚刚设置
self.view.window?.rootViewController?.dismiss(animated: false, completion: nil)animated: false -
它们是在导航控制器中还是以模态方式呈现?如果在导航控制器中,
self.navigationController?.popToRootViewController(animated: true) -
@KishanBhatiya 已经尝试过了,同样的问题。
-
@aledap 不,那是错误的。更改根视图控制器将关闭并清除所有导航堆栈。而呈现根视图控制器不会清除当前的视图控制器,它只会将根视图控制器作为新的视图控制器推送到它们之上。了解其中的区别。
-
尝试使用
let navigationController = UINavigationController(rootViewController: ViewController)let appdelegate = UIApplication.shared.delegate as! AppDelegateappdelegate.window!.rootViewController = navigationController设置rootViewController
标签: ios swift xcode uiviewcontroller uinavigationcontroller