2014-05-05 51 views
0

我在Main.storyboard中創建了一個UIViewController,我試圖從UIImagePickerController委託方法中以編程方式呈現它。但我收到的消息:UIViewController不從故事板呈現

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?

回答

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]; 
    }]; 
} 
+0

謝謝你,工作。我只是通過UIViewController編程指南試圖找出問題。 – Michael

+0

完美答案:) –

相關問題