سؤال

In the old days before storyboards I was able to create my own UIWindow instance in -application:didFinishLaunchingWithOptions:.

I have a UIWindow subclass with special needs which I want to use with a new Xcode project. But my app delegate method is empty and still there is magically a UIWindow.

There is a Main.storyboard file. But looking inside it I only see a UIViewController. No reference to a UIWindow.

main.m also has no mention of a UIWindow.

Who creates the UIWindow and how can I force it to instantiate my subclass instead?

هل كانت مفيدة؟

المحلول

If the App Delegate's window property is nil, the app creates a window for you.

To make a custom window, implement a window getter in the App Delegate.

From the docs for App Delegate's window property:

Implementation of this property is required if your app’s Info.plist file contains the UIMainStoryboardFile key. Fortunately, the Xcode project templates usually include a synthesized declaration of the property automatically for the app delegate. The default value of this synthesized property is nil, which causes the app to create a generic UIWindow object and assign it to the property. If you want to provide a custom window for your app, you must implement the getter method of this property and use it to create and return your custom window.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top