문제

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?

도움이 되었습니까?

해결책

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];
    }];
}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top