您好,我在使用 rootViewController 时遇到了困难,我在下面留下了一些代码片段并附有说明,请告诉我。
如果我像下面那样做,它就可以工作并且一切正常。
private func presentLogin() {
log.info("presenting login..")
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let appDelegate = UIApplication.shared.delegate as! AppDelegate
let vc = storyboard.instantiateViewController(withIdentifier: "LoginViewController") as! LoginViewController
vc.modalPresentationStyle = .fullScreen
appDelegate.window!.rootViewController = vc
present(vc, animated: false)
}
在那之后,如果我执行下面的代码,ios只显示白色空白页..
private func presentMain() {
log.info("presenting main..")
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let appDelegate = UIApplication.shared.delegate as! AppDelegate
let vc = storyboard.instantiateViewController(withIdentifier: "MainTabBarController") as! MainTabBarController
vc.modalPresentationStyle = .fullScreen
appDelegate.window!.rootViewController = vc
present(vc, animated: false)
}
但是当我删除代码时
appDelegate.window!.rootViewController = vc
一切正常。
换句话说,下面的代码只在第一次运行。
appDelegate.window!.rootViewController = vc
为什么?我错过了什么?,我不明白..
答案 0 :(得分:1)
似乎有很多关于根视图控制器交换的bugs。切换根视图控制器也是一种不常见的“导航”方式。我会推荐一种不同的方法: