【发布时间】:2020-12-22 19:10:00
【问题描述】:
您好,我正在为 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
为什么?我错过了什么?,我不明白..
【问题讨论】:
标签: ios window rootviewcontroller