title: UIViewController.navigationController becomes nil
body: <p>I bumped into a problem where <code>UIViewController.navigationController</code> becomes <code>nil</code> and I'm desperately trying to find an answer to this one.</p>
  
  <p>The <code>UINavigationController</code> gets setup in the application delegate:</p>
  
  <pre><code>- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
      self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
  
      self.rootViewController = [[RootViewController alloc] initWithNibName:@"RootView" bundle:nil];
  
      UINavigationController* navigationController = [[UINavigationController alloc] initWithRootViewController:self.rootViewController];
      [self.window addSubview:navigationController.view];
  
      [self.window makeKeyAndVisible];
  
      return YES;
  }
  </code></pre>
  
  <p>When the <code>RootViewController</code> is appearing, the <code>self.navigationController</code> member is set and I can use it to hide the navigation bar, like so:</p>
  
  <pre><code>- (void)viewWillAppear:(BOOL)animated {
      NSLog( @"self = %@, self.navigationController = %@", self, self.navigationController );
      [self.navigationController setNavigationBarHidden:YES animated:NO];
  }
  </code></pre>
  
  <p>The debug output shows values for <code>self</code> and <code>self.navigationController</code>.</p>
  
  <p>When a button is clicked in this controller, <code>self</code> remains the same value indeed but <code>self.navigationController</code> is now <code>nil</code>:</p>
  
  <pre><code>- (IBAction)buttonClicked:(id)sender {
          NSLog( @"self = %@, self.navigationController = %@", self, self.navigationController );
          // here, self.navigationController is nil, so
          // [self.navigationController pushViewController:...] doesn't work :-(
  }
  </code></pre>
  
  <p>I've seen dozens of questions regarding this problem and the answer is always that the <code>UIViewController</code> is not part of a <code>UINavigationController</code>. Since accessing the <code>navigationController</code> in <code>viewWillAppear</code> works fine, I believe something else must be going on. Do you have any pointers? I'll happily provide more detail if necessary.</p>