Reputation: 2652
I am learning how to manipulate view displays programmatically, I manage to display a new view in my appDelegate with the following block of code:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
UINavigationController *navController = [[UINavigationController alloc] init];
loginController = [[LoginController alloc] init];
[navController pushViewController:loginController animated:NO];
[self.window addSubview:navController.view];
[self.window makeKeyAndVisible];
return YES; }
I have added a button in this view that will remove this current view and supposedly programmatically display a new view, however, I only managed to remove the view and not display the new view.
my code to display the second view is the following:
HomeController *homeView = [[HomeController alloc] init];
[self.window addSubview:homeView.view];
[homeView.view release];
Please advise.. I've been searching for hours to no avail, using Switch Views Programmatically, iPhone Views, removeSuperview..
Basically I want to create a simple login flow, at app start I will display my first view (login form), after successful login I want to discard the old view and display the second view which is my home page.
Upvotes: 1
Views: 632
Reputation: 726549
You are on the right track with using the UINavigationController
. In fact, you are almost there.
You already have two view controllers - one for the login page, and one for the home page. In the didFinishLaunchingWithOptions:
, push both controllers onto the UINavigationController
's stack: first the "home" controller, then the "login" one. Once the login controller detects that the login has been successful, call popViewControllerAnimated:
or popToRootViewControllerAnimated:
to get to the home page.
Upvotes: 2