iOS 13: Swift - 'Set application root view controller programmatically' does not work

后端 未结 14 1058
北恋
北恋 2020-12-01 01:43

I have following code in my AppDelegate.swift to setup root view controller for an iOS application. But it does not work. It follows Target structure (defined under General

14条回答
  •  抹茶落季
    2020-12-01 02:35

    I tried the following approach and it's working for me in iOS 13 and also tested on iOS 12.4.2 from Xcode 11.

    func resetRoot() {
                guard let rootVC = UIStoryboard.init(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "ViewController") as? ViewController else {
                    return
                }
                let navigationController = UINavigationController(rootViewController: rootVC)
    
                UIApplication.shared.windows.first?.rootViewController = navigationController
                UIApplication.shared.windows.first?.makeKeyAndVisible()
         }
    

提交回复
热议问题