如何在 swift 5 中设置实例化后可以推送的初始 viewController

how can I set initial viewController that can push after instantiate in swift 5

提问人:Unknown Hush 提问时间:11/22/2019 更新时间:11/22/2019 访问量:90

问:

使用此代码后,我无法从初始 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()
iOS Swift iPhone UIAnageController AppDelegate

评论

0赞 vpoltave 11/22/2019
这是什么意思?- 我推不开
0赞 vpoltave 11/22/2019
instantiateViewController此方法不返回 initial,此方法返回 -instantiateInitialViewController()

答:

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()