In one of my apps, I'm calling a viewController from the application didReceiveLocalNotification
method. The page loads successfully, but it shows a warning as :
Warning: Attempt to present <blankPageViewController: 0x1fda5190> on
<ViewController: 0x1fd85330> whose view is not in the window hierarchy!
My code is as follows :
-(void) application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification {
blankPageViewController *myView = [[blankPageViewController alloc]
initWithNibName:@"blankPageViewController" bundle: nil];
myView.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self.viewController presentViewController:myView animated:NO completion:nil];
}
Finally I solved that issue with the following code.
I was having a similar issue, I was calling the presentViewController from within my AppDelegate.m when the application entered the foreground:
This worked no problem as it dismisses the view controller first (regardless of what views have been pushed onto it) if it is present before presenting the Login view controller. If not then I can just present the Login view controller straight away.
As per my assumption, I am feeling like you are trying to present
myView
fromself.viewController
beforeself.viewController
is attached or placed in window hierarchy. So just make sure to presentmyView
afterself.viewController
gets appear/attached to window.Why can't a modal view controller present another in viewDidLoad?
Edge Case:
Some people may find this through Google and it is worth pointing out that sometimes this error is raised if you are loading a view up as the root view controller which is not labelled as the initial view in Storyboard (& another view is) and then you load another view on top. Eg, in Log In Views which are loaded programmatically from within the
applicationdidfinish...
method of the App Delegate. Simply change the initial view (drag the arrow in Storyboard) to the appropriate one for your hierarchy. Esoteric, vague, but worth pointing out.it could be because the viewcontroller's view is not currently loaded in window hierarchy when VC is presented...