applications expected to have a root view controller console

I am getting a message within the console when I run my app that says:

2011-11-16 19:17:41.292 Juice[8674:707] Applications are expected to have a root view controller at the end of application launch

I have heard from others that this has to do with the method didFinishLaunchingWithOptions

If anyone has any suggestions for why I am getting this error, it would be much appreciated.

My code for the method:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {    

    // Override point for customization after application launch.

    [window addSubview:tabBarController.view];
    [window makeKeyAndVisible];

    [[UIApplication sharedApplication] setStatusBarHidden:NO withAnimation:UIStatusBarAnimationFade];

    return YES;
}

Solution 1:

You should replace the

[window addSubview:tabBarController.view];

to

[self.window setRootViewController:tabBarController];

Maybe you built your project with 'Empty Application' and forgot to set the rootViewController in your didFinishLaunchingWithOptions (which exists in your AppDelegate.m).

However, if you build your project with 'Single View Application' or some other type, the project will set the rootViewController via xib by default (which might be a MainWindow.xib in your project).

Solution 2:

I had the same problem on iOS 5, after adding a storyboard to an "empty" project. It turns out I had to remove all the lines in AppDelegate.m that set values to self.window.

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    //self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    // Override point for customization after application launch.
    //self.window.backgroundColor = [UIColor whiteColor];
    //[self.window makeKeyAndVisible];
    return YES;
}

Solution 3:

If you have MainWindow.xib, make sure you set Main Interface in Target's summary to MainWindow.

Solution 4:

The way I got this error Applications are expected to have a root view controller at the end of application launch to disappear, was to ensure the loadView method in my root view controller was calling [super loadView]. Hope this helps someone.