Question

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.

Était-ce utile?

La solution 2

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];

Autres conseils

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.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top