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

后端 未结 14 1099
北恋
北恋 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:38

    I did two things. Firstly I set a Notification into SceneDelegate, then when I needed to change the RootViewController I did a Notification Post and it worked. But it's an anwful solution.

    After that

    My boss recommended me to change the Controllers of the NavigationController, something like this:

    func logged() {
        let mainStoryboard: UIStoryboard = UIStoryboard(name: "MainTabViewController", bundle: nil)
        let mainVC = mainStoryboard.instantiateInitialViewController()
    
        self.navigationController?.setViewControllers([mainVC!], animated: false)
    }
    

    I know that perhaps it's not the best solution, but I see it cleaner.
    I'm working now on iOS 13 and I didn't want to use deprecated things.

提交回复
热议问题