I get the following error in my console:
Applications are expected to have a root view controller at the end of application launch
None of the above suggestions solved my problem. Mine was this:
Add:
window.rootViewController = navigationController;
after:
[window addSubview:navigationController.view];
in my appdelegate's
- (void)applicationDidFinishLaunching:(UIApplication *)application {
i got this problems too. i got my project run in xcode4.2.1. i've read all comments up there, but no one is cool for me. after a while, i find that i commented a piece of code.
//self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
then i uncommented it. everything is ok for me. hope this would helpful for you guys.
Make sure you have this function in your application delegate.
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions: (NSDictionary *)launchOptions {
return YES;
}
Make sure didFinishLaunchingWithOptions returns YES. If you happened to remove the 'return YES' line, this will cause the error. This error may be especially common with storyboard users.
If you use MTStatusBarOverlay, then you'll get this error.
MTStatusBarOverlay creates an additional window ([[UIApplication sharedApplication] windows) which doesn't have a root controller.
This doesn't seem to cause a problem.
OrdoDei gave a correct and valuable answer. I'm adding this answer only to give an example of a didFinishLaunchingWithOptions
method that uses his answer as well as accounting for the others’ comments regarding Navigation Controller.
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
// Instantiate the main menu view controller (UITableView with menu items).
// Pass that view controller to the nav controller as the root of the nav stack.
// This nav stack drives our *entire* app.
UIViewController *viewController = [[XMMainMenuTableViewController alloc] init];
self.navigationController = [[UINavigationController alloc] initWithRootViewController:viewController];
// Instantiate the app's window. Then get the nav controller's view into that window, and onto the screen.
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// [self.window addSubview:self.navigationController.view];
// The disabled line above was replaced by line below. Fixed Apple's complaint in log: Application windows are expected to have a root view controller at the end of application launch
[self.window setRootViewController:self.navigationController];
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];
return YES;
}
Replace in AppDelegate
[window addSubview:[someController view]];
to
[self.window setRootViewController:someController];