0

当我需要从视图控制器显示导航控制器时出现错误,如下所示:

“警告:尝试呈现不在窗口层次结构中的视图!”

代码如下:

UIStoryboard* storyboard = [UIStoryboard storyboardWithName:@"NavMain" bundle:nil];
UINavigationController * mainViewController = [storyboard instantiateInitialViewController];
mainViewController.modalPresentationStyle = UIModalPresentationFormSheet;
[self presentViewController:mainViewController animated:YES completion:NO];

如何修复错误或在实现情节提要时出现任何错误?我使用两个故事板从main.storyboardNavMain.storyboard

4

1 回答 1

0

The error means that self's view hasn't loaded yet. You want to call this code after the view has loaded. So put it in:

    -(void)viewDidAppear:(BOOL)animated;
于 2013-10-09T04:35:17.910 回答