Application windows are expected to have a root view controller

╄→尐↘猪︶ㄣ 提交于 2019-12-13 05:23:51

问题


I have received a project from a client that I need to compile, but when I run it gives error Application windows are expected to have a root view controller at the end of application launch and EXC_BAD_Access (code=2, address=0x0)

as far as I know this is due to application:didFinishLaunchWithOptions: in the AppDelegate, but the problem with my project is that there is no AppDelegate file.

EDIT:

I tried to run the project on Xcode 4.5.1 now it is giving the error address doesn't contain a section that points to a section in a object file.


回答1:


The problem is that there is no AppDelegate file. That is usually where the root view controller is set

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
  self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
  // Override point for customization after application launch.
  self.viewController = [[[ViewController alloc] initWithNibName:@"ViewController" bundle:nil] autorelease];

  // set root view controller
  self.window.rootViewController = self.viewController;
  [self.window makeKeyAndVisible];
  return YES;
}



回答2:


I also experienced the "Application windows are expected to have a root view controller" error message.

If you are using a storyboard and you have verified:

  1. The app delegate application:didFinishLaunchingWithOptions method is returning TRUE and doing nothing else.
  2. The view controller is set in IB to be the initial view controller.
  3. The storyboard is appropriately set on the TARGETS Summary tab.

Verify that you have not created a "view" UIView @property and @synthezised it in the view controller implementation. I experienced this and through a lengthy process of elimination had my DOH moment when I realized I had created a "view" UIView property named exactly like the one IB had created and linked to the view controller.

Hope this helps.



来源:https://stackoverflow.com/questions/13488372/application-windows-are-expected-to-have-a-root-view-controller

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!