UIViewController没有从故事板中呈现

时间:2014-05-05 22:03:01

标签: ios ios7 uiviewcontroller storyboard

我在Main.storyboard中创建了一个UIViewController,我试图从UIImagePickerController委托方法中以编程方式呈现它。但我收到的消息是:

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

代码:

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

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

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

如何从故事板中正确呈现UIViewController?

1 个答案:

答案 0 :(得分:2)

如果您的图像选择器以模态方式呈现,您可能需要先将其关闭,然后才能显示自定义视图控制器。像这样:

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