0

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

Moin Ahmed
  • 2,898
  • 21
  • 33
user831098
  • 1,803
  • 6
  • 27
  • 47
  • Just trying to clarify are you trying to add a navigation controller from navmain storyboard to a UIViewController in the main storyboard. May I ask what is the reasoning behind wanting to do this? – Ben Avery Oct 09 '13 at 04:22
  • When start to load application, I want a loading page (UIViewController) to download some data. After finish download, I need to present another view which is navigation controller for login page. – user831098 Oct 09 '13 at 05:50
  • http://stackoverflow.com/questions/18929864/how-do-i-change-the-navigation-bar-color-in-ios-7/18929980#18929980 – Rajneesh071 Oct 09 '13 at 06:56

1 Answers1

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;
Justin Ramos
  • 116
  • 10