简体   繁体   中英

Present a navigation view from view controller - IOS 7

I got an error when I need to present a navigation controller from view controller like below:

"Warning: Attempt to present on whose view is not in the window hierarchy!"

The code as below:

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

How to fix the bugs or does I had any error when implement storyboard? I use two storyboard from main.storyboard to NavMain.storyboard

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;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM