Search code examples
iphoneobjective-cuiviewmainwindow

"Application windows are expected to have a root view controller at the end of application launch" error only on iPad


I am trying to convert my iPhone only application to a Universal application. I switched the devices to Universal and let Xcode do it's thing making a MainWindow-iPad.xib for me, and now when I run the app in the iPhone simulator it works fine, but when I run it in the iPad simulator I get a white screen and the Application windows are expected to have a root view controller at the end of application launch error. I have read some other posts about this same problem but none of them are just limited to one device.

Here is my application:didFinishLaunchWithOptions: method:

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

 /* some dropbox setup stuff */


// INIT VIEW AND CORE DATA
RootViewController *rootViewController = [[RootViewController alloc] initWithNibName:@"RootViewController" bundle:nil];

NSManagedObjectContext *context = [self managedObjectContext];
if (!context) {
    // Handle the error.
}

rootViewController.managedObjectContext = context;

UINavigationController *aNavigationController = [[UINavigationController alloc] initWithRootViewController:rootViewController];
self.navigationController = aNavigationController;

[_window addSubview:[_navigationController view]];
[_window makeKeyAndVisible];

[rootViewController release];
[aNavigationController release];

return YES;
}

EDIT: I just have one root view controller that is sized for iPhone called RootViewController. But it should still load in shouldn't it? Or if it shouldn't how do I create one for iPad?


Solution

  • Change the following line:

    [_window addSubview:[_navigationController view]];
    

    to:

    _window.rootViewController = _navigationController;
    

    or, if you need iOS 3 compatibility:

    if ([_window respondsToSelector:@selector(setRootViewController:)]) {
        _window.rootViewController = _navigationController;
    } else {
        [_window addSubview:_navigationController.view];
    }