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

后端 未结 30 1305
野的像风
野的像风 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:41
    • Select your "Window" in your Nib File
    • In "Attributes Inspector" Check "Visible at Launch"

    image![]

    • This happens when your nib file is created manually.
    • This fix works for regular nib mode - not storyboard mode
    0 讨论(0)
  • 2020-11-22 07:41

    There was a slight change around iOS 5.0 or so, requiring you to have a root view controller. If your code is based off older sample code, such as GLES2Sample, then no root view controller was created in those code samples.

    To fix (that GLES2Sample, for instance), right in applicationDidFinishLaunching, I create a root view controller and attach my glView to it.

    - (void) applicationDidFinishLaunching:(UIApplication *)application
    {
      // To make the 'Application windows are expected
      // to have a root view controller
      // at the end of application launch' warning go away,
      // you should have a rootviewcontroller,
      // but this app doesn't have one at all.
      window.rootViewController = [[UIViewController alloc] init];  // MAKE ONE
      window.rootViewController.view = glView; // MUST SET THIS UP OTHERWISE
      // THE ROOTVIEWCONTROLLER SEEMS TO INTERCEPT TOUCH EVENTS
    }
    

    That makes the warning go away, and doesn't really affect your app otherwise.

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

    I began having this same issue right after upgrading to Xcode 4.3, and only when starting a project from scratch (i.e. create empty project, then create a UIViewController, and then Create a separate nib file).

    After putting ALL the lines I used to, and ensuring I had the correct connections, I kept getting that error, and the nib file I was trying to load through the view controller (which was set as the rootController) never showed in the simulator.

    I created a single view template through Xcode and compared it to my code and FINALLY found the problem!

    Xcode 4.3 appears to add by default the method -(void)loadView; to the view controller implementation section. After carefully reading the comments inside it, it became clear what the problem was. The comment indicated to override loadView method if creating a view programmatically (and I'm paraphrasing), otherwise NOT to override loadView if using a nib. There was nothing else inside this method, so in affect I was overriding the method (and doing nothing) WHILE using a nib file, which gave the error.

    The SOLUTION was to either completely remove the loadView method from the implementation section, or to call the parent method by adding [super loadView].

    Removing it would be best if using a NIB file as adding any other code will in effect override it.

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

    I solved the problem by doing the following (none of the other solutions above helped):

    From the pulldown menu associated with "Main Interface" select another entry and then reselect "MainWindow" then rebuild.

    enter image description here

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

    This happened to me. Solved by editing .plist file. Specify the Main nib file base name.(Should be MainWindow.xib). Hope this will help.

    enter image description here

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

    To add to Mike Flynn's answer, since upgrading to Xcode 7 and running my app on an iOS 9 device, I added this to my (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions

    // Hide any window that isn't the main window
    NSArray *windows = [[UIApplication sharedApplication] windows];
    for (UIWindow *window in windows) {
        if (window != self.window) {
            window.hidden = YES;
        }
    }
    
    0 讨论(0)
提交回复
热议问题