title: How to get root view controller?
body: <p>I need an instance of root view controller. </p>
  
  <p>I tried those approaches:</p>
  
  <pre><code>UIViewController *rootViewController = (UIViewController*)[[[UIApplication sharedApplication] keyWindow] rootViewController];
  </code></pre>
  
  <p>Returns:  <strong>null</strong>:</p>
  
  <p>Also when I try to get an array of controllers:</p>
  
  <pre><code>NSArray *viewControllers = self.navigationController.viewControllers;
  </code></pre>
  
  <p>It returns only one controller, but it isn't my root view controller.</p>
  
  <p>If I try to take from navigation controller:</p>
  
  <pre><code>UIViewController *root = (UIViewController*)[self.navigationController.viewControllers objectAtIndex:0];
  </code></pre>
  
  <p>Returns:  <strong>null</strong>:</p>
  
  <p>Any ideas why?  What else could I try to get an instance of my root view controller?</p>
  
  <p>Thanks.</p>