当我需要从视图控制器中显示导航控制器时出现错误,如下所示:
“警告:尝试显示其视图不在窗口层次结构中!”
代码如下:
UIStoryboard* storyboard = [UIStoryboard storyboardWithName:@"NavMain" bundle:nil];
UINavigationController * mainViewController = [storyboard instantiateInitialViewController];
mainViewController.modalPresentationStyle = UIModalPresentationFormSheet;
[self presentViewController:mainViewController animated:YES completion:NO];
如何修复错误或在实现故事板时是否有任何错误?
我使用了从main.storyboard
到NavMain.storyboard
答案 0 :(得分:0)
该错误表示self
的视图尚未加载。您希望在加载视图后调用此代码。所以把它放进去:
-(void)viewDidAppear:(BOOL)animated;