Tejas
Tejas

Reputation: 272

Examples where makeKeyAndVisible is not required for UIWindow

I was wondering in all iOS applications we have to write makeKeyAndVisible for our UIWindow object. So is there a example where we dont want our application to makeKeyAndVisible.

If we always require it for any application, then why dint apple automatically write it for us, like they did for @synthesize as part of iOS 6?

Upvotes: 2

Views: 3845

Answers (3)

Xiao Ming
Xiao Ming

Reputation: 131

If you use storyboard to launch your app it's not required to call makeKeyAndVisible.

You can try to create a new project in Xcode 6. The project is not using makeKeyAndVisible, and you will get nil if you try to get keyWindow.

Upvotes: 2

Dhruv Goel
Dhruv Goel

Reputation: 2775

Apple handles makeKeyAndVisible automatically with storyboards

With storyboards, iOS performs the following steps:

  • It instantiates a window for you.
  • It loads the main storyboard and instantiates its initial view controller.
  • It assigns the new view controller to the window’s rootViewController property and then makes the window visible on the screen.

Upvotes: 11

rmaddy
rmaddy

Reputation: 318944

An app can have more than one window. The call to makeKeyAndVisible is used to specify which one is current.

Despite the fact that most apps only have one window, there is no way to assume that your primary window is to be the key window. Therefore you must explicitly call makeKeyAndVisible.

Upvotes: 10

Related Questions