Perform Segue from App Delegate swift

前端 未结 7 1033
野的像风
野的像风 2020-12-06 00:53

I need to launch a view controller from the app delegate.

In the way you would perform a segue between view controllers.

I have an if statement that if true

相关标签:
7条回答
  • 2020-12-06 01:28

    Here's what you'd do if your rootViewController did NOT inherit from UINavigationViewController:

    Basically you check what the currently presented tab is and then push from THAT view controller, rather than the rootViewController that inherits from UITabBarController.

            let root = self.window?.rootViewController as UITabBarController
    
            switch(root.selectedIndex){
            case 0:
                root.viewControllers?[0].pushViewController(viewController, animated: true)
                break;
            case 1:
                root.viewControllers?[1].pushViewController(viewController, animated: true)
                break
            default:
                println("Error presenting ViewController")
                break;
            }
    

    My application has an initial/rootViewController that inherits from UITabBarController, each of it's UITabBar Relationship Controllers inherit from UINavigationController, allowing me to pushViewController from them.

    0 讨论(0)
提交回复
热议问题