0

I'm working on an objective-c iOS application that was first created in 2011 some updates and changes where done in 2013. Now I'm supposed to make this work since it's crashing with an error:

Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Application windows are expected to have a root view controller at the end of application launch'

in AppDelegate i have checked :

[self.window setRootViewController:viewAfterLaunchScreen];

according to this answer "Application windows are expected to have a root view controller at the end of application launch" error when running a project with Xcode 7, iOS 9

after debugging i have noticed that the application crashes after running the rootViewController at viewWillAppear.

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
if ([[DAL GetPreferences:@"FIRST"] isEqualToString:@"1"])
{
    LoginViewController *lvc3 = [[LoginViewController alloc] initWithNibName:@"LoginViewController" bundle:nil];
    [self.window setRootViewController:lvc3];
    [lvc3 release];
}
else if(_window.rootViewController == nil){

    PagingViewController *lvc2 = [[PagingViewController alloc] initWithNibName:@"PagingViewController" bundle:nil];
    [self.window setRootViewController:lvc2];
    [lvc2 release];
}
[DAL SavePreference:@"FIRST" :@"1"];
[self.window makeKeyAndVisible];
return YES; }
Community
  • 1
  • 1
R.AlAli
  • 85
  • 2
  • 10
  • 1
    Possible duplicate of ["Application windows are expected to have a root view controller at the end of application launch" error when running a project with Xcode 7, iOS 9](http://stackoverflow.com/questions/30884896/application-windows-are-expected-to-have-a-root-view-controller-at-the-end-of-a) – MD. Dec 21 '16 at 11:12
  • @Mahesh i have checked this answer before posting my question and i have already mentioned that i have checked setRootViewController. – R.AlAli Dec 21 '16 at 12:28
  • Show your `didFinishLaunchingWithOptions` method. – MD. Dec 21 '16 at 12:33
  • @Mahesh please check the edited post – R.AlAli Dec 21 '16 at 12:45
  • try `LoginViewController *lvc3 = [[LoginViewController alloc] initWithNibName:@"LoginViewController" bundle:nil]; [self.window setRootViewController:lvc3];` before return YES. if problem is still there then check that your viewcontroller is not nil. – MD. Dec 21 '16 at 12:49
  • the problem is still not solved @Mahesh thank you for your time – R.AlAli Dec 21 '16 at 13:11

1 Answers1

0

How old is this "old" project? If it's more than a few years, do you still have:

[window addSubview:viewController.view];

You should instead replace it with:

[window setRootViewController:viewController];
amit_donga
  • 224
  • 1
  • 9