0

The App I created for iOS 4 does not work once run on iOS 5. I am receiving the following error:

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

How can I update the following code to fix this error?

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {  

UINavigationController *navcon = [[UINavigationController alloc] init] 
TSViewController *pvc = [[TSViewController alloc] init];

[navcon pushViewController:pvc animated:NO];
[navcon setNavigationBarHidden:YES animated:NO];
    [pvc release];
[window addSubview:navcon.view];


return YES;

}

JulianF
  • 59
  • 2
  • 8

1 Answers1

1

[window setRootViewController:navcon]; instead of addSubview.

Tim
  • 14,447
  • 6
  • 40
  • 63
  • I tried that and now I'm getting the following error " *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UILayoutContainerView _preferredInterfaceOrientationGivenCurrentOrientation:]: unrecognized selector sent to instance 0x35d860'" – JulianF Nov 14 '11 at 07:55
  • 1
    Did you make sure you did `[window setRootViewController:navcon];` and NOT `[window setRootViewController:navcon.view];`? – Tim Nov 14 '11 at 08:32
  • Yes I tried both ways, however when I use 'navcon' and not 'navcon.view' I still get the "Applications are expected to have a rootViewController" error. – JulianF Nov 14 '11 at 15:08
  • Sorry, after you call `setRootViewController:` you have to call `[window makeKeyAndVisible]`. – Tim Mar 25 '13 at 20:32