简体   繁体   中英

show a login screen before Tab bar controller?

i am designing an iphone application which should be display login screen initially, after that it should display tab bar controller with 5 tabs. Am able to launch login screen initially, but after that am unble to show tab bar controller, kindly help me out with the source code guys. here is my code: this is a view based application

application.M

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

    // Override point for customization after app launch 
       [window addSubview:viewController.view]; 
    [window addSubview:tabBarController. view];   
    [window makeKeyAndVisible];
    LoginView *loginView=[[LoginView alloc]initWithNibName:@"LoginView" bundle:nil];
    [window addSubview:loginView.view];
}  

by doing this the tab bar controller is displaying at the bottom of the login screen initially.And also am unable to switch between the tab bar items.

What you can do is the following.

Launch the Tabbar as the main screen and then before the view is loaded or displayed show the logon screen and dismiss the logon screen after successful log on.

EDIT: For a code example look at code provided by Maulik

Try to do the following:

[window makeKeyAndVisible];
LoginView *loginView=[[LoginView alloc] initWithNibName:@"LoginView" bundle:nil];
[window addSubview:loginView.view];

You will want to show the loggin first. After the login done, you should send a message to your app delegate so he can switch between your login view and your tabBarController:

-(void)loginFinished{   
    window.rootViewController=tabBarController;
}

I advise you to:

1 - Have IBOutlets for your LoginViewController and UITabBarViewController, so you can easly use them.

2- Use a notifcation, so your app delegate knows when to switch the controllers.

Assuming you have TabBarController class by sub classing UITabBarController .

You can also push tab bar controller after the Login view complete its job.

In Login.m file

- (void) doLogin
{
  if(login)
  {
     TabBarController *aTabBarController = [[TabBarController alloc] initWithNibName:@"TabBarController" bundle:nil];
     [self.navigationController pushViewController:aTabBarController animated:YES];
     [aTabBarController release];    
  }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM