问题
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:
- The app delegate application:didFinishLaunchingWithOptions method is returning TRUE and doing nothing else.
- The view controller is set in IB to be the initial view controller.
- 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