title: iPhone iOS what is the correct way to implement login / logout workflow with a storyboard?
body: <p>I have the following workflow defined within my iPhone project storyboard: </p>
  
  <ul>
  <li>Login view controller is set as root view controller in a storyboard.  </li>
  <li>Login has a separate workflow for login and setting up account. </li>
  <li>Both workflows end up modally presenting tab bar with the main app content</li>
  <li>For subsequent app launches, I programmatically determine the correct controller to instantiate in <code>appDidFinishLaunching:</code></li>
  <li>For subsequent app use the tab bar with main content is the root view controller (programmatically set)</li>
  </ul>
  
  <p>Now I would like to implement a "logout" process - a button wipes all the user data and brings the user back to the original "login/set up account" screen.</p>
  
  <p>I'm running into an issue where due to multiple states of the application I need to have multiple paths to return to the home screen. For example:</p>
  
  <pre><code>                      UIViewController* parent = self.presentingViewController;
                        UIViewController* grandparent = self.presentingViewController;
                        [self.presentingViewController dismissViewControllerAnimated:YES completion:^{
                            DLog(@"first dismiss");
  
                            DLog(@"%@",parent);
                            DLog(@"%@",grandparent);
  
                            [parent dismissViewControllerAnimated:YES completion:^{
                                DLog(@"second dismiss");
                                [grandparent.navigationController popToRootViewControllerAnimated:YES];
                            }];
                        }];
  </code></pre>
  
  <p><strong>How would I go about implementing the login/logout logic defined above?</strong> </p>
  
  <p><strong>Is there a correct way to completely collapse the view hierarchy that is currently that is currently on screen and replace it with another one?</strong> </p>
  
  <p>I'm thinking of this one: </p>
  
  <pre><code> [self.window setRootViewController:tabBarViewController];
  </code></pre>
  
  <p>But am not sure if this will properly unload all resources used by the old rootViewController stack that I'm detaching.</p>