title: Re-assigning RootViewController after successful login
body: <p>My iOS app opens with a login prompt. Once the user logs in, it switches to the main view.</p>
  
  <p>In application:didFinishLaunchingWithOptions, I set the RootViewController to a LoginViewController. The LoginViewController has the AppDelegate as its delegate:</p>
  
  <pre><code>LoginViewController *login = [[LoginViewController alloc] init];
  [login setDelegate:self];
  [[self window] setRootViewController:login];
  </code></pre>
  
  <p>If the login is successful, the LoginViewController calls the AppDelegate's userDidLogin method:</p>
  
  <pre><code>if([[self delegate] respondsToSelector:@selector(userDidLogin)]) {
      [[self delegate] userDidLogin];
  }
  </code></pre>
  
  <p>userDidLogin creates a new UINavigationController and assigns it as the RootViewController:</p>
  
  <pre><code>- (void)userDidLogin
  {
      MainRecordViewController *mainRecordViewController = [[MainRecordViewController alloc] init];
      UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:mainRecordViewController];
      [[self window] setRootViewController:navController];
  }
  </code></pre>
  
  <p>By adding an NSLog to the LoginViewController's dealloc method, it appears that the LoginViewController is destroyed at that stage and that execution continues as expected.</p>
  
  <p>I haven't done anything to explicitly close the LoginViewController, just relied on the assumption that assigning a new RootViewController will mean that the old one disappears and is tidied away by ARC.</p>
  
  <p>Can I rely on that always being the case? Is this a sensible approach?</p>
  
  <p>Thanks in advance.</p>
  
  <p>James</p>