提问人:Unknown Hush 提问时间:11/22/2019 更新时间:11/22/2019 访问量:90
如何在 swift 5 中设置实例化后可以推送的初始 viewController
how can I set initial viewController that can push after instantiate in swift 5
问:
使用此代码后,我无法从初始 viewController 推送
self.window = UIWindow(框架:UIScreen.main.bounds)
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let initialViewController = storyboard.instantiateViewController(withIdentifier: Identifier)
self.window?.rootViewController = initialViewController
self.window?.makeKeyAndVisible()
答:
1赞
MBT
11/22/2019
#1
必须在 UINavigationController 中嵌入 UIViewController。试试这个:
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let initialViewController = storyboard.instantiateViewController(withIdentifier: Identifier)
let navController = UINavigationController(rootViewController: initialViewController)
self.window?.rootViewController = navController
self.window?.makeKeyAndVisible()
评论
instantiateViewController
此方法不返回 initial,此方法返回 -instantiateInitialViewController()