Sergey Grishchev
Sergey Grishchev

Reputation: 12051

"Application windows are expected to have a root view controller" conditional appearance

I'm writing an app for iPhone using Xcode 4.5 and iOS6. I'm also creating a new UIWindow to be able to manage the area of the status bar (to display messages there, etc.) I'm using storyboards and my appDelegate method looks like this:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    return YES;
}

The message does not appear in the console when I put it in the method called viewDidAppear:

- (void)viewDidAppear:(BOOL)animated     {

    if (!window) {
        window = [[SGStatusBar alloc] initWithFrame:CGRectZero];
        window.frame = [[UIApplication sharedApplication] statusBarFrame];
        window.alpha = 0.5f;

        [self.view.window makeKeyAndVisible]; // has to be main window of app
        window.hidden = NO;
    }  
}

The same method, put in the viewDidLoad gives a warning in the console:

2012-12-27 11:34:20.838 NewApp[433:c07] Application windows are expected to have a root view controller at the end of application launch

Is this because I've created a new UIWindow? Why the difference between those two methods is so big?

And, most importantly, how can I get rid of this warning while putting the code in the viewDidLoad method?

EDIT:

I have encountered the same problem here, but it's not the way I'd like to solve it (it's actually the way I'm solving it right now)

I've tried setting my current ViewController as my window's root view controller by doing this:

ViewController *vcB = [[UIViewController alloc] init];
window.rootViewController = vcB;

But I keep getting a warning that says:

Incompatible pointer types initializing 'ViewController *__strong' with an expression of type 'UIViewController *'

Upvotes: 1

Views: 1068

Answers (2)

Nikita P
Nikita P

Reputation: 4246

Set window.rootViewController property .

Upvotes: 1

iMash
iMash

Reputation: 1188

Add the following code to your delegate.h and delegate.m files.

AppDelegate.h

@property (strong, nonatomic) UIWindow *window;
@property (strong, nonatomic) YourViewController *viewController;

AppDelegate.m

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
    // Override point for customization after application launch.
    self.viewController = [[[YourViewcontroller alloc] initWithNibName:@"YourViewcontroller" bundle:nil] autorelease];
    self.window.rootViewController = self.viewController;
    [self.window makeKeyAndVisible];
    return YES;
}

Hope it works.

Upvotes: 0

Related Questions