Why in AppDelegate

I need to present a view controller from AppDelegate , so I wrote the following code:

 let storyboard = UIStoryboard(name: "Main", bundle: nil) let authViewController = storyboard.instantiateViewControllerWithIdentifier("ViewController") as ViewController if let keyWindow = UIApplication.sharedApplication().keyWindow { keyWindow.rootViewController = authViewController } 

Unfortunately, window and keyWindow are nil . Why?

+6
source share
1 answer

You need to create a window yourself if you do not use the option of the main interface:

 window = UIWindow(frame:UIScreen.mainScreen().bounds) 

Swift 3.0

 self.window = UIWindow(frame: UIScreen.main.bounds) 

Then call your code above using window .

Finally, call makeKeyAndVisible() on the window.

+24
source

Source: https://habr.com/ru/post/978585/


All Articles