title: IOS App switch views after login
body: <p>I'm learning to develop for IOS in Xcode 5. The app uses a master-detail template which it populates from a simple API i've written in PHP.</p>
  
  <p>I want users to log into the app so that the app can make requests to the API on behalf of the user. I'll explain what i've set up (which could be entirely wrong):</p>
  
  <p>I've created a login view and made it the initial view. My login view is controlled by a class named LoginViewController which contains a 'logUserIn' method. When the 'Login' button in the view is pressed this method sends a post request to the API to check the user's credentials, my app then reads the response to see if they are valid. This is where i'm stuck.</p>
  
  <p>After i've determined I have a valid set of credentials I want to do 2 things:</p>
  
  <ol>
  <li>Save the credentials for use on subsequent requests</li>
  <li>Switch from the login view back to the master-detail view</li>
  </ol>
  
  <p>If when the app loads there are already valid credentials saved the loginViewController should switch straight to the master-detail view.</p>
  
  <p>Here's my LoginViewController.m:</p>
  
  <pre><code>#import "NTFYLoginViewController.h"
  
  @interface NTFYLoginViewController ()
  
  @end
  
  @implementation NTFYLoginViewController
  
  - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
  {
      self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
      if (self) {
          // Custom initialization
      }
      return self;
  }
  
  - (void)viewDidLoad
  {
      [super viewDidLoad];
  
      // Attempt to read saved credentials
      // Check they still work
      // Switch to master-detail view if credentials exist and are valid
  }
  
  - (void)didReceiveMemoryWarning
  {
      [super didReceiveMemoryWarning];
      // Dispose of any resources that can be recreated.
  }
  
  - (IBAction)logUserIn:(id)sender
  {
      NSString *username = self.usernameField.text;
      NSString *password = self.passwordField.text;
  
      // The code here talks to the api and checks the credentials, 
      // i've swapped it for pseudo code below as the actual code 
      // is irrelevant
  
      if(user is logged in)
      { 
          // Save credentials
          // Switch to master-detail view
      }
  
      // Display login error    
  }
  
  @end
  </code></pre>
  
  <p>So, here is what I actually want to know:</p>
  
  <ol>
  <li>Is this the best way to go about doing this?</li>
  <li>How can I switch to the MasterViewController from my LoginViewController?</li>
  </ol>