Perform Segue from App Delegate swift

前端 未结 7 1066
野的像风
野的像风 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:25

    You can't actually perform a segue from the AppDelegate since a segue is a transition from one scene to another. One thing you can do however is instantiate a new view controller and present it from the AppDelegate. Something similar to the following should work...

    func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
        // Override point for customization after application launch.
        var storyboard = UIStoryboard(name: "Main", bundle: nil)
        var viewController: MasterViewController = storyboard.instantiateViewControllerWithIdentifier("viewController") as MasterViewController
    
        window?.rootViewController = viewController
        window?.makeKeyAndVisible()
    
        return true
    }
    

提交回复
热议问题