title: Showing login view controller before main tab bar controller
body: <p>I'm creating an iPad app with a tab bar controller that requires login.  So on launch, I want to show a LoginViewController and if login is successful, then show the tab bar controller.  This is how I implemented an initial test version (left out some typical header stuff, etc)...</p>
  
  <p>AppDelegate.h:</p>
  
  <pre><code>@interface AppDelegate_Pad : NSObject 
          &lt;UIApplicationDelegate, LoginViewControllerDelegate&gt; {
      UIWindow *window;
      UITabBarController *tabBarController;
  }
  @property (nonatomic, retain) IBOutlet UIWindow *window;
  @property (nonatomic, retain) IBOutlet UITabBarController *tabBarController;
  @end
  </code></pre>
  
  <p>AppDelegate.m:</p>
  
  <pre><code>@implementation AppDelegate_Pad
  @synthesize window;
  @synthesize tabBarController;
  - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
      LoginViewController_Pad *lvc = [[LoginViewController_Pad alloc] initWithNibName:@"LoginViewController_Pad" bundle:nil];
      lvc.delegate = self;
      [window addSubview:lvc.view];
      //[lvc release];
      [window makeKeyAndVisible];
      return YES;
  }
  - (void)loginViewControllerDidFinish:(LoginViewController_Pad *)loginViewController {
      [window addSubview:tabBarController.view];
  }
  - (void)dealloc {...}
  @end
  </code></pre>
  
  <p>LoginViewController_Pad.h:</p>
  
  <pre><code>@protocol LoginViewControllerDelegate;
  @interface LoginViewController_Pad : UIViewController {
      id&lt;LoginViewControllerDelegate&gt; delegate;
  }
  @property (nonatomic, assign) id &lt;LoginViewControllerDelegate&gt; delegate;
  - (IBAction)buttonPressed;
  @end
  @protocol LoginViewControllerDelegate
  -(void)loginViewControllerDidFinish:(LoginViewController_Pad *)loginViewController;
  @end
  </code></pre>
  
  <p>LoginViewController_Pad.m:</p>
  
  <pre><code>@implementation LoginViewController_Pad
  @synthesize delegate;
      ...
  - (IBAction)buttonPressed
  {
      [self.view removeFromSuperview];
      [self.delegate loginViewControllerDidFinish:self];
  }
      ...
  @end
  </code></pre>
  
  <p>So the app delegate adds the login view controller's view on launch and waits for login to call "did finish" using a delegate.  The login view controller calls removeFromSuperView before it calls didFinish.  The app delegate then calls addSubView on the tab bar controller's view.</p>
  
  <p>If you made it up to this point, thanks, and I have three questions:  </p>
  
  <ol>
  <li><p><strong>MAIN QUESTION:</strong> Is this the right way to show a view controller before the app's main tab bar controller is displayed?  Even though it seems to work, is it a proper way to do it?  </p></li>
  <li><p>If I comment out the "lvc release" in the app delegate then the app crashes with EXC_BAD_ACCESS when the button on the login view controller is pressed.  Why?  </p></li>
  <li><p>With the "lvc release" commented out everything seems to work but on the debugger console it writes this message when the app delegate calls addSubView for the tab bar controller: <strong>Using two-stage rotation animation. To use the smoother single-stage animation, this application must remove two-stage method implementations.</strong>  What does that mean and do I need to worry about it?</p></li>
  </ol>
  
  <p><strong>UPDATE:</strong>
  As suggested by lucius, changed it to modally show the login view controller from the app delegate.  This appears to be a cleaner solution.  Code changed as follows...</p>
  
  <p>AppDelegate.m:</p>
  
  <pre><code>- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
      [window addSubview:tabBarController.view];
      [window makeKeyAndVisible];
  
      LoginViewController_Pad *lvc = [[LoginViewController_Pad alloc] initWithNibName:@"LoginViewController_Pad" bundle:nil];
      lvc.delegate = self;
      [self.tabBarController presentModalViewController:lvc animated:NO];
      [lvc release];
  
      return YES;
  }
  -(void)loginViewControllerDidFinish:(LoginViewController_Pad *)loginViewController {
      [self.mainTabBarController dismissModalViewControllerAnimated:NO];
  }
  </code></pre>
  
  <p>LoginViewController_Pad.m:</p>
  
  <pre><code>- (IBAction)buttonPressed
  {
      //do NOT removeFromSuperview, delegate will dismiss
      //[self.view removeFromSuperview];
      [self.delegate loginViewControllerDidFinish:self];
  }
  </code></pre>