2

I've set up a void method which is called from another class if the user touches the button. However, I got this error with "whose view is not in window hierarchy" and then I found this: whose view is not in the window hierarchy. I just want to call the method below but I got this error and it doesn't show me the navigatoncontroller. It says Warning: Attempt to present <UINavigationController: 0xae34f10> on <ViewController: 0xae1f200> whose view is not in the window hierarchy! I don't know if this is possible to call the method from the viewDidAppear or from somewhere that it only works if the button was tapped on the other view before. If I call a NSLog in the method it shows me the NSLog in the output. Only the presenting of the navController doesn't seems to work. I would be happy if someone could help me with this.

My method:

- (void) launchGalleryView
{

    MWPhotoBrowser *browser = [[MWPhotoBrowser alloc] initWithDelegate:self];

    // Set browser options.
    browser.wantsFullScreenLayout = YES;
    browser.displayActionButton = NO;


    UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:browser];

    NSMutableArray *photos = [[NSMutableArray alloc] init];
    MWPhoto *photo;
    photo = [MWPhoto photoWithFilePath:[[NSBundle mainBundle] pathForResource:@"calculator" ofType:@"jpg"]];
    photo.caption = @"The calculator is soo beauteful...";
    [photos addObject:photo];

    self.photos = photos;

    [self presentModalViewController:navController animated:YES];

}

Just forgot to say: The MWPhotoprowser is a class which actually does't matter.

Thanks in advance.

Community
  • 1
  • 1
MasterRazer
  • 1,377
  • 3
  • 16
  • 40

2 Answers2

2

The error message is pretty clear -- you're trying to present the controller from this class, but the class that has the button you pressed is the one whose view is in the view hierarchy. You either need to present it from the class with the button, or get back to this class however you're doing that, and then call it after viewDidAppear.

rdelmar
  • 103,982
  • 12
  • 207
  • 218
  • if you look at this you see that I have to call it in another class: http://stackoverflow.com/questions/13777395/display-navigationcontroller-on-top – MasterRazer Dec 16 '12 at 00:36
  • and then this happend http://stackoverflow.com/questions/13888062/whose-view-is-not-in-window-hierarchy-issue – MasterRazer Dec 16 '12 at 00:37
  • @NoahRaissi, Not sure what you mean. If you want to present the navigation controller from the class where this method resides, then that view controller's view needs to be on screen. Do you want that? If so, the button method could just set a flag which you could check for in the viewDidLoad method -- if the flag is set, you call this method. – rdelmar Dec 16 '12 at 00:40
  • could I send you my project, that you can take a look at it? – MasterRazer Dec 16 '12 at 00:42
  • Sure - rdelmar@comcast.net – rdelmar Dec 16 '12 at 00:42
  • I put it on dropbox and send you the link ;) – MasterRazer Dec 16 '12 at 00:44
  • OMG it take about 15 min. is that okay for you? – MasterRazer Dec 16 '12 at 00:46
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/21197/discussion-between-rdelmar-and-noah-raissi) – rdelmar Dec 16 '12 at 00:47
  • lets continue in chat http://chat.stackoverflow.com/rooms/21197/discussion-between-rdelmar-and-noah-raissi – MasterRazer Dec 16 '12 at 12:51
0

i checked your project.. wasn't able to sort out the proper issue..

but i tried a hack and it worked..

replace this line with

[self presentModalViewController:navController animated:YES];

this

[[[[[UIApplication sharedApplication] delegate] window] rootViewController] presentModalViewController:navController animated:YES];
Shubhank
  • 21,721
  • 8
  • 65
  • 83
  • Yuk! Rather than go back down to the root view controller - it's a better idea to present it from the current root view controller rather than just ignoring the problem altogether. – Abizern Dec 16 '12 at 16:58
  • i do agree..it is just a hack.. don't think it as a proper solution..i didn't have all the time to go deep into the problem. – Shubhank Dec 16 '12 at 18:27