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)...
AppDelegate.h:
@interface AppDelegate_Pad : NSObject
<UIApplicationDelegate, LoginViewControllerDelegate> {
UIWindow *window;
UITabBarController *tabBarController;
}
@property (nonatomic, retain) IBOutlet UIWindow *window;
@property (nonatomic, retain) IBOutlet UITabBarController *tabBarController;
@end
AppDelegate.m:
@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
LoginViewController_Pad.h:
@protocol LoginViewControllerDelegate;
@interface LoginViewController_Pad : UIViewController {
id<LoginViewControllerDelegate> delegate;
}
@property (nonatomic, assign) id <LoginViewControllerDelegate> delegate;
- (IBAction)buttonPressed;
@end
@protocol LoginViewControllerDelegate
-(void)loginViewControllerDidFinish:(LoginViewController_Pad *)loginViewController;
@end
LoginViewController_Pad.m:
@implementation LoginViewController_Pad
@synthesize delegate;
...
- (IBAction)buttonPressed
{
[self.view removeFromSuperview];
[self.delegate loginViewControllerDidFinish:self];
}
...
@end
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.
If you made it up to this point, thanks, and I have three questions:
MAIN QUESTION: 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?
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?
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: Using two-stage rotation animation. To use the smoother single-stage animation, this application must remove two-stage method implementations. What does that mean and do I need to worry about it?