1

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???

Community
  • 1
  • 1
Karthik Varma
  • 59
  • 2
  • 11
  • you need to accept answers to your previous questions, it is discouraging for people to put effort into answering your questions if you can't be bothered to accept their answers. – Andrey Zverev Dec 15 '11 at 11:17

4 Answers4

4

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];
  }
NIKHIL
  • 2,719
  • 1
  • 26
  • 50
aherlambang
  • 14,290
  • 50
  • 150
  • 253
  • Yes, a modal view controller is the correct way to handle it, but you would set the `animated` parameter to NO so that it's on-screen and ready to go when the app launches. – Darren Dec 15 '11 at 05:41
3

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];    
  }
}
Maulik
  • 19,348
  • 14
  • 82
  • 137
  • can i declare Ui tab bar controller as Iboutlet. – Karthik Varma Dec 15 '11 at 05:20
  • Can i comment this view did load method in the view controller.m- (void)viewDidLoad { LoginView *loginView=[[LoginView alloc]initWithNibName:@"LoginView" bundle:nil]; i have declared login view in my applicataion didFinishLaunching. after running this i can see a small part of my login view had left out some space at the bottom [self.view addSubview:loginView.view]; [super viewDidLoad]; } – Karthik Varma Dec 15 '11 at 05:31
  • I think you want show tab bar after successful login right ? if so, then you can ignore view did load method so you can show tab bar after login. – Maulik Dec 15 '11 at 05:33
  • No let LoginView get displayed – Maulik Dec 15 '11 at 05:36
  • ya u r right i wanted to shoe the tab bar after the sucessful login........can i use tab bar controller in the login view controller, becoz i have declare iboutlet tab bar controller in the delegate.. will that work or i have to declare tabbar controller as i iboutlet in the loginview,h file – Karthik Varma Dec 15 '11 at 05:57
2

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.

gurooj
  • 2,100
  • 4
  • 21
  • 25
2

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

Dipak Chaudhari
  • 655
  • 4
  • 8