I know there are lot of discussions around this warning and we should be presenting the view controller only after presenting view controller is completely presented and added in view hierarchy. All these rules are followed and I am still getting this warning when presenting second modal view controller.
This the complete sequence of actions happening here:
- On app launch, initialized and added base view controller to window.
- From base view controller, on tap on a button, modally presented first view controller.
- From first view controller, on tap on a button, modally presented second view controller. Once dismissed, I need to show first view controller so I am not dismissing first VC and then presenting second VC from base VC.
Warning in console:
2015-03-11 13:15:43.467 MyApp[597:84839] Warning: Attempt to present <MyCustomNavigationViewController: 0x15d6a8920> on <MyFirstModalViewController: 0x15d67cc60> whose view is not in the window hierarchy!
Thoughts?
Below is my code [Not showing button handlers; took code from within the calling methods]:
// Present base view controller
self.window.backgroundColor = [UIColor whiteColor];
self.primaryViewController = [[MyParentViewController alloc] init];
self.navigationController = [[MyCustomNavigationViewController alloc] initWithRootViewController:self.primaryViewController];
[self.navigationController.navigationBar setBarStyle:UIBarStyleBlack];
self.window.rootViewController = self.navigationController;
[self.window makeKeyAndVisible];
// Present first view controller modally from base view controller
MyFirstModalViewController *firstModal = [[MyFirstModalViewController alloc] init];
MyCustomNavigationViewController *aNavigationController = [[MyCustomNavigationViewController alloc] initWithRootViewController:firstModal];
[aNavigationController.navigationBar setBarStyle:UIBarStyleBlack];
[self presentViewController:aNavigationController animated:YES completion:nil];
// Present second view controller modally from first view controller: On user tap on a button
MySecondModalViewController *secondModal = [[MySecondModalViewController alloc] init];
MyCustomNavigationViewController *aNavigationController = [[MyCustomNavigationViewController alloc] initWithRootViewController:secondModal];
[aNavigationController.navigationBar setBarStyle:UIBarStyleBlack];
[self presentViewController:aNavigationController animated:YES completion:nil];