我在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?
答案 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];
}];
}