Question

I created a UIViewController in Main.storyboard and I am trying to present it programmatically from inside an UIImagePickerController delegate method. But I am receiving the message:

Warning: Attempt to present <DAAnalysisViewController: 0x8b99960> on 
<DAViewController: 0x8b35300> whose view is not in the window hierarchy!

Code:

- (void)imagePickerController:(UIImagePickerController *)picker 
didFinishPickingMediaWithInfo:(NSDictionary *)info{

    DAAnalysisViewController *asdf = [[UIStoryboard storyboardWithName:@"Main" bundle:nil] 
   instantiateViewControllerWithIdentifier:@"1"];

    [self presentViewController:asdf animated:YES completion:nil];
}

How do I properly present a UIViewController from a storyboard?

Was it helpful?

Solution

If your image picker is being presented modally, you may need to dismiss it first and THEN you can display your custom view controller. Something like this:

- (void)imagePickerController:(UIImagePickerController *)picker
didFinishPickingMediaWithInfo:(NSDictionary *)info
{
    [self dismissViewControllerAnimated:YES completion:^{
        UIStoryboard *sb = [UIStoryboard storyboardWithName:@"Main" bundle:nil];

        DAAnalysisViewController *asdf = [sb instantiateViewControllerWithIdentifier:@"1"];

        [self presentViewController:asdf animated:YES completion:nil];
    }];
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top