0
votes

I have a simple application with two subclasses of UIViewController.

I want to change the view being displayed by my application's UIWindow by calling a method from one of my UIViewController subclasses.

Essentially I'm just messing around and I'm trying to construct a simple test application with a login screen, that after a user enters credentials a main view is presented. I'm not too familiar with the window and view mechanisms of iOS programming, and I'm currently reading http://developer.apple.com/library/ios/#documentation/WindowsViews/Conceptual/ViewPG_iPhoneOS/WindowsandViews/WindowsandViews.html#//apple_ref/doc/uid/TP40009503-CH2-SW1 and attempting to learn a bit about it.

1
Also, would I want to instantiate both classes when the application loads or is it okay to wait until the login test completes to instantiate the main view that will be presented to the user?Casey Flynn

1 Answers

1
votes

If this is for the purpose of a login screen, you should add the main view controller to window directly, and add the login view controller as a modal view inside the main view controller.

Inside applicationDidFinishLaunching...

MainViewController *mainViewController = [[MainView....... // instantiate UINavigationController *navController = [[UINavigationController alloc]initWithRootViewController:mainViewController];
[mainViewController release]; 
[window addSubview:navController.view];

Inside MainViewController

-(void)viewWillAppear:(BOOL)animated
{
    LoginViewController *loginVC = .... //instantiate
    [self.navigationController presentModalViewController:loginVC  animated:NO];
    [loginVC release];
}

if login successful,

[self dismissModalViewControllerAnimated:YES];