Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I have same issue as explained in this question:

Where can I change the window my app uses from UIWindow to my own subclass "MyWindow" with storyboard?

My question is how do i implement a 'window' getter method in my app delegate that returns 'MyWindow' subclass? Or maybe there is other ways to assign my subclass to my app's main window?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
433 views
Welcome To Ask or Share your Answers For Others

1 Answer

UIWindow in a Storyboard project can be subclassed as explained in Apple's UIApplicationDelegate reference:

window
When a storyboard is being used, the application must present the storyboard by adding it to a window and putting that window on-screen. The application queries this property for the window. The retained reference to the window by this property is necessary to keep the window from being released. If the value of the property is nil (the default), the application creates a generic instance of UIWindow and assign it to this property for the delegate to reference. You may implement the getter method of this protocol to provide the application with a different window.

In other words in your AppDelegate implementation simply add the following getter

Objective-C

- (MyCustomWindow *)window
{    
    static MyCustomWindow *customWindow = nil;
    if (!customWindow) customWindow = [[MyCustomWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    return customWindow;
}

Swift

var customWindow: MyCustomWindow?    
var window: UIWindow? {
    get {
        customWindow = customWindow ?? MyCustomWindow(frame: UIScreen.mainScreen().bounds)
        return customWindow
    }
    set { }
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...