简体   繁体   中英

Root view controller in a Storyboard

I'm playing around with a single-window template. I have a classic MainStoryboard.storyboard file and I have only 1 view controller (which is an Initial View Controller all by default)

What I do is I try to implement the behaviour from this example and the Xcode tells me this:

Application windows are expected to have a root view controller at the end of application launch

I don't understand what I'm doing wrong. Here's the piece of code where I create a new UIWindow :

UIWindow *overlayWindow = [[UIWindow alloc] init];
    overlayWindow = [[ACStatusBarOverlayWindow alloc] initWithFrame:CGRectZero];
    overlayWindow.hidden = NO;

And of course my appDelegate starts with this:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    // Override point for customization after application launch.
    return YES;
}

What am I doing wrong?

You should make your window key and visible by

[overlayWindow makeKeyAndVisible];

as suggested in the very same example you linked.

EDIT

This the code you are using

UIWindow *overlayWindow = [[UIWindow alloc] init];
overlayWindow = [[ACStatusBarOverlayWindow alloc] initWithFrame:CGRectZero];
overlayWindow.hidden = NO;

The first line its useless and potentially it is the one which is causing the warning. You are creating a UIWindow instance and than throwing it away in the next line.

Remove it and just do:

UIWindow *overlayWindow = [[ACStatusBarOverlayWindow alloc] initWithFrame:CGRectZero];
overlayWindow.hidden = NO;

Also you should assign a root view controller to the newly created window, by

overlayWindow.rootViewController = self.window.rootViewController;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM