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

后端 未结 30 1828
野的像风
野的像风 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:35

    I run into the same problem recently, when building a project with ios5 sdk. At first it was building and running properly, but after that the error appeared.
    In my case the solution was rather simple.
    What was missing, was that somehow the Main Interface property in the summary tab of my application target got erased. So I needed to set it again.


    If this is not the point, and if the tabBarController is still nil, you can always programmatically create your window and root controller. As a fallback I added the following code to my project

    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
    { 
        if (!window && !navigationController) {
            NSLog(@"Window and navigation controller not loaded from nib. Will be created programatically.");
            self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
            UIViewController *viewController1, *viewController2;
            viewController1 = [[[FirstViewController alloc] initWithNibName:@"FirstViewController_iPhone" bundle:nil] autorelease];
            viewController2 = [[[SecondViewController alloc] initWithNibName:@"SecondViewController_iPhone" bundle:nil] autorelease];
    
            self.tabBarController = [[[UITabBarController alloc] init] autorelease];
            self.tabBarController.viewControllers = [NSArray arrayWithObjects:viewController1, viewController2, nil];
            self.window.rootViewController = self.tabBarController;
    
        }
        else {
            [window addSubview:[tabBarController view]];
        }
        [self.window makeKeyAndVisible];
        return YES;
    }
    

    This will work only if sho's solution is implemented also.

提交回复
热议问题