【问题标题】:UIViewController not presenting from storyboardUIViewController 未从情节提要中呈现
【发布时间】:2014-06-22 08:31:42
【问题描述】:

我在 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?

【问题讨论】:

    标签: ios ios7 uiviewcontroller storyboard


    【解决方案1】:

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

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

    【讨论】:

    • 谢谢你,成功了。我只是通过 UIViewController 编程指南试图找出问题。
    猜你喜欢
    • 2021-04-18
    • 1970-01-01
    • 2012-06-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-08-21
    • 1970-01-01
    相关资源
    最近更新 更多