Donal Rafferty
Donal Rafferty

Reputation: 19826

iPhone - What is the correct way to setup app navigation for different types of views/windows?

As a newcomer to objective-c and IOS one of the hardest things I've found to get my head around is how to load new views and move between what I want to display to the user at various stages of the application.

I have started by creating an app with a Tab Bar controller at the bottom and a navigation bar at the top, I have grasped this and how to load different views for each tab bar item.

However I want to expand the app so the following happens,

The user loads the app, first off a plain login screen appears, if the user enters correct details the app moves to my current setup of the tab bar and navigation bar if they enter incorrect details they go to a plain error page.

So I'm not sure what I need to change in my app to achieve this, do I need to create a new window and put a view in it for the login screen and then how do I load my current setup?

Do I change my Main Interface to a new window? Or do I have to change my current MainWindow.xib to load the login view and then re create my current setup in a different xib file?

Upvotes: 1

Views: 215

Answers (2)

user141302
user141302

Reputation:

Usually We can use one UIWindow only in iPhone SDK.So We have to handle all things through one UIWindow.You can use the following code in your AppDelegate.m file.When user clicks login button, you can remove login page and show Tab bar controller

- (void)applicationDidFinishLaunching:(UIApplication *)application {    

// Override point for customization after app launch    
     [window addSubview:viewController.view];// you log in page
     [window addSubview:tabController.view];//Your Tab bar controller
[window makeKeyAndVisible];

}

-(IBAction)Login_buttonClicking
{
[viewController.view removeFromSuperview];
}

Upvotes: 1

knl
knl

Reputation: 1404

As you may already know, views are usually managed by corresponding subclasses of UIViewController. They can present their views in multiple ways, e.g. modal (the new view slides up and covers the previous view), in a tab of a UITabBarController or as part of a navigational hirachy with a UINavigationController. Concerning your case, I recommend loading your standard tab bar controller and let it present your login view modally. When the user presses the login button, the modal view gets dismissed and slides down to show the actual content in the tab bar controller:

- (void)applicationDidFinishLaunching:(UIApplication *)application {

    LoginViewController *loginViewController = [[LoginViewController alloc] init];
    [tabBarController presentModalViewController:loginViewController animated:NO];
    [loginViewController release];

    [window addSubview:tabBarController.view];
    [window makeKeyAndVisible];
}

The Login Button in the LoginViewController must then call:

- (void)loginSuccessful {
    [self.parentViewController dismissModalViewController];
}

This solution makes the login screen cover the tab bar controller view when the app launches and will make it slide down out of the screen when the user has logged in.

Upvotes: 2

Related Questions