title: Warning: Attempt to present <CustomViewController> on <UINavigationontroller> whose view is not in the window hierarchy
body: <p><em>I know this has been asked a million times, but I couldn't find a suitable answer in those many questions that I've examined.</em></p>
  
  <p>I have a custom view controller, and I'm trying to display the view controller when the user taps a button (so no "infamous <code>viewDidLoad</code> problem" here).</p>
  
  <p>Here is my code that runs when the user taps the button: (I have the NIB for the view controller, and I have a navigation controller)</p>
  
  <pre><code>ICLoginViewController *loginViewController = [[ICLoginViewController alloc] initWithNibName:@"ICLoginViewController" bundle:[NSBundle mainBundle]];
  //assuming we have a navigation controller.
  
  UINavigationController *navigationController= (UINavigationController*)[[UIApplication sharedApplication] keyWindow].rootViewController;
  [navigationController.topViewController presentViewController:loginViewController animated:YES completion:nil];
  </code></pre>
  
  <p>I'm getting the <code>Warning: Attempt to present &lt;ICLoginViewController: 0xa08a810&gt; on &lt;UINavigationController: 0xa45de70&gt; whose view is not in the window hierarchy!</code> error when I try to present the view controller. Nothing happens on screen. If I tap multiple times I get the same error, and still nothing happens. I've set a breakpoint and verified that <code>navigationController</code> and <code>navigationController.topViewController</code> are not <code>nil</code>. I' using storyboard (if it helps) but not for the custom view controller that I'm trying to display. (I want to make it an app-independent library in the long run, so I'm not referencing any app-specific modules within) Why am I getting this error?</p>