Question

Possible Duplicate:
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];
}

view controller.M

- (void)viewDidLoad
{   LoginView *loginView=[[LoginView alloc]initWithNibName:@"LoginView" bundle:nil];
    [self.view addSubview:loginView.view];

    [super viewDidLoad];
}

where i am doing wrong, am unable to show tab bat controller after login screen. when the application is launched i can see tab bar controler at the bottom of the login screen initially. how to avoid that????? help me with code and also after clicking on login button, how to dismiss loginview and how to load tab bar controller???

Was it helpful?

Solution

Do Following Steps-

  1. If you chose view based application , then open main (root) .xib in which change ViewController property for xib select login view controller .
  2. Class name as login view controller .
  3. In AppDelegate file replace the main (root) viewController to login view controller.
  4. In login view controller create a button for login .

  5. -(IBAction)loginButtonPressed:(id)sender { SampleViewController *sampleVC=[[SampleViewController alloc] initWithNibName:@"SampleViewController" bundle:nil]; [self presentModalViewController:sampleVC animated:YES]; }

OTHER TIPS

Why don't you set the window to add a UITabBarController and then just present the login view as a modal view controller initially when you need the login to show.

-(void)applicationDidFinishLaunching:(UIApplication *)application
{    
  // Override point for customization after app launch 

  [window addSubview:tabBarController. view];   
  [window makeKeyAndVisible];
  LoginView *loginView=[[LoginView alloc]initWithNibName:@"LoginView" bundle:nil];
  [tabBarController.view presentModelViewcontroller: loginView animated:YES];
  }

Don't add your tab bar here

-(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];
}

you should add your tab bar in the LoginView after login done. For example

In Login.m file

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

You could consider a different method for implementing your login screen. You should make the tab bar controller visible on the main view in the app delegate, and just set a BOOL value in the app delegate to keep track of whether the user is logged in. And if that value is false, present the login screen as a new view controller using presentModalViewController: from within the tab bar controller. In iPhone apps, the tab bar becomes the index of your app, it should always be present in the main view. And think of the login screen as a gate that only appears for those logged out.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top