title: Best practices for Storyboard login screen, handling clearing of data upon logout
body: <p>I'm building an iOS app using a Storyboard. The root view controller is a Tab Bar Controller. I'm creating the login/logout process, and it's mostly working fine, but I've got a few issues. I need to know the BEST way to set all this up.</p>
  
  <p>I want to accomplish the following:</p>
  
  <ol>
  <li>Show a login screen the first time the app is launched. When they login, go to the first tab of the Tab Bar Controller.</li>
  <li>Any time they launch the app after that, check if they are logged in, and skip straight to the first tab of the root Tab Bar Controller.</li>
  <li>When they manually click a logout button, show the login screen, and clear all the data from the view controllers.</li>
  </ol>
  
  <p>What I've done so far is set the root view controller to the Tab Bar Controller, and created a custom segue to my Login view controller. Inside my Tab Bar Controller class, I check whether they are logged in inside the <code>viewDidAppear</code> method, and a perform the segue: <code>[self performSegueWithIdentifier:@"pushLogin" sender:self];</code> </p>
  
  <p>I also setup a notification for when the logout action needs to be performed: <code>[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(logoutAccount) name:@"logoutAccount" object:nil];</code></p>
  
  <p>Upon logout, I clear the credentials from the Keychain, run <code>[self setSelectedIndex:0]</code> and perform the segue to show the login view controller again.</p>
  
  <p>This all works fine, but I'm wondering: <strong>should this logic be in the AppDelegate?</strong> I also have two issues:</p>
  
  <ul>
  <li><strong>The first time they launch the app</strong>, the Tab Bar Controller shows briefly before the segue is performed. I've tried moving the code to <code>viewWillAppear</code> but the segue will not work that early.</li>
  <li>When they logout, all the data is still inside all the view controllers. If they login to a new account, the old account data is still displayed until they refresh. <strong>I need a way to clear this easily on logout.</strong></li>
  </ul>
  
  <p>I'm open to reworking this. I've considered making the login screen the root view controller, or creating a navigation controller in the AppDelegate to handle everything... I'm just not sure what the best method is at this point.</p>