Question

I got menuVC that contain from composition of other VC's, one of this is loginViewController, how to go to loginViewController from menuVC? Or it is a best way to load VC from method? My code :

MenuViewController * menuViewController = [storyboard instantiateViewControllerWithIdentifier:@"MenuViewController"];
 [menuViewController presentViewController:menuViewController.loginViewController animated:YES completion:nil];

I can do it like this:

UIStoryboard * storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
MenuViewController * menuViewController = [storyboard instantiateViewControllerWithIdentifier:@"MenuViewController"];
[menuViewController showLoginViewController];

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

Was it helpful?

Solution

You cannot present a view controller modally when the app has not been presented in view yet. You can present it in the viewDidAppear method of menu view controller. You will have to do it in viewDidAppear and not in viewDidLoad or viewWillAppear as the view that you are presenting it on is not in the current window hierarchy, basically the same issue that you are having by doing it in the app delegate. If you want it already shown when the app launches just choose set animated to NO. Let me know if you need more help.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top