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

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

    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.

提交回复
热议问题