1

I am trying to load a viewController if there are no accounts logged in however it gives me this error Warning: Attempt to present <DefaultViewController: 0xb96cac0> on <MainViewController: 0xb95c320> whose view is not in the window hierarchy! Here is the code that I am using right now:

BOOL returnAllOff = [[User data] returnAllOff];

if (returnAllOff) {
    DefaultViewController *viewController =[[DefaultViewController alloc]
    init];
    UIViewController *presentingController = [[[[UIApplication sharedApplication] delegate] window] rootViewController];
    [presentingController presentViewController:viewController animated:YES completion:nil];

}
Prad
  • 469
  • 1
  • 8
  • 28
  • http://stackoverflow.com/questions/13888062/whose-view-is-not-in-window-hierarchy-issue –  Aug 23 '13 at 06:29
  • http://stackoverflow.com/questions/11862883/whose-view-is-not-in-the-window-hierarchy –  Aug 23 '13 at 06:30
  • I tried the solution in the first link but i got the same issue – Prad Aug 23 '13 at 06:33
  • Where is that code? The error is quite clear about the reason. – Wain Aug 23 '13 at 06:39
  • Would i Have to add DefaultViewController in the mainviewcontroller class. FYI i am using storyboards. – Prad Aug 23 '13 at 06:40

2 Answers2

1

Actually this is the correct way of loading a ViewController from AppDelegate..

    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];

    DefaultViewController *viewController = [[DefaultViewController alloc] initWithNibName:@"DefaultViewController" bundle:nil];
    self.window.rootViewController = viewController;
    [self.window makeKeyAndVisible];
Ahmed Z.
  • 2,329
  • 23
  • 52
  • It now gives this issue instead... `*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Could not load NIB in bundle: 'NSBundle (loaded)' with name 'DefaultViewController''` – Prad Aug 23 '13 at 06:42
  • you are using Storyboards? – Ahmed Z. Aug 23 '13 at 06:43
  • I added that line now, however when the view loads its all black even though there are 2 buttons and the page is filled with color. @preetam – Prad Aug 23 '13 at 07:04
1

Try this one by importing DefaultViewController in appDElegate.

self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
DefaultViewController *viewController = [[DefaultViewController alloc] init];
self.window.rootViewController = viewController;
[self.window makeKeyAndVisible];
Preetam Jadakar
  • 4,479
  • 2
  • 28
  • 58