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

后端 未结 30 1303
野的像风
野的像风 2020-11-22 06:42

I get the following error in my console:

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

相关标签:
30条回答
  • 2020-11-22 07:28

    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 {
    
    0 讨论(0)
  • 2020-11-22 07:28

    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.

    0 讨论(0)
  • 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.

    0 讨论(0)
  • 2020-11-22 07:28

    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.

    0 讨论(0)
  • 2020-11-22 07:28

    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;
    }
    
    0 讨论(0)
  • 2020-11-22 07:29

    Replace in AppDelegate

     [window addSubview:[someController view]];
    

    to

      [self.window setRootViewController:someController];
    
    0 讨论(0)
提交回复
热议问题