-2

This is a view based application.

in delegate.m file I have done like this to launch login screen initially:

- (void)applicationDidFinishLaunching:(UIApplication *)application
{
  [window addSubview:viewController.view];
  [window makeKeyAndVisible];

  LoginView *loginView=[[LoginView alloc]initWithNibName:@"LoginView" bundle:nil];

  [window addSubview:loginView.view];
}

By adding the above code I have launched login screen sucessfully, but at the bottom of my login screen I can see a space left out.

How can the tab bar controller get launched after sucessful login?

i have creatd a method called login in my LoginView.m file:

-(void)login
{
  if(login)
  {
    TabBarController *tabBarController = [[TabBarController alloc] initWithNibName:@"TabBarController" bundle:nil];

    [self.view addSubView: aTabBarController.view];
  }

    [aTabBarController release];

Please help me out of this with the appropriate code.

phi
  • 10,634
  • 6
  • 53
  • 88
Karthik Varma
  • 59
  • 2
  • 11
  • Possible duplicate of this question : http://stackoverflow.com/questions/6034893/show-a-login-screen-before-a-tab-bar-controller – Niko Dec 15 '11 at 10:40
  • 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:16

3 Answers3

1

Your login view (or it's controller if you have one which it looks like you don't) should tell the appDelegate to swap the RootViewController to be a taBarController. You do NOT want the loginview to be trying to add a tabBar as a child of itself.

ader
  • 5,403
  • 1
  • 21
  • 26
1

One way of doing it is creating a tabbarcontroller like normal in your appdelegate and set it as rootviewcontroller:

TOTabBarController *tabBarController = [[TOTabBarController alloc] init];

UIViewController *vc1 = [[UIViewController alloc] initWithNibName:nil bundle:nil];
UIViewController *vc2 = [[UIViewController alloc] initWithNibName:nil bundle:nil];
UIViewController *vc3 = [[UIViewController alloc] initWithNibName:nil bundle:nil];

UINavigationController *vc2_nc = [[UINavigationController alloc] initWithRootViewController:vc2];
UINavigationController *vc3_nc = [[UINavigationController alloc] initWithRootViewController:vc3];

NSArray *viewControllers = [NSArray arrayWithObjects:vc1, vc2_nc, vc3_nc, nil];

[tabBarController setViewControllers:viewControllers];

//set tabbarcontroller as rootviewcontroller
[[self window] setRootViewController:tabBarController];

Then display the login screen modally (without animation) if the user is not logged in:

if (not logged in) {
    UIViewController *lvc_nc = [[UIViewController alloc] init];
    [[[self window] rootViewController] presentModalViewController:lvc_nc animated:NO];
}

Hope that helps!

chourobin
  • 4,004
  • 4
  • 35
  • 48
  • remember in your loginview controller that you send the message to dismiss the modalview once the person signs in: [self dismissModalView...] – chourobin Dec 15 '11 at 12:04
  • to dismiss my loginview once after the sucessful login what i need to do can i say[self.view removeFromSuperView] in my method?? and also what does ModalViewController Mean??? – Karthik Varma Dec 15 '11 at 12:08
  • That is not necessary. It will automatically unload the view when you dismiss it. Inside your loginViewController, write [self dismissModalViewControllerAnimated:YES]; when the person logs in. – chourobin Dec 15 '11 at 12:33
  • http://developer.apple.com/library/ios/#featuredarticles/ViewControllerPGforiPhoneOS/ModalViewControllers/ModalViewControllers.html – chourobin Dec 15 '11 at 12:33
  • If it worked out for you, you should click on the green checkmark next to my answer or upvote it to accept the answer. – chourobin Dec 16 '11 at 08:20
1

you have to create on method in appDelegate like.. and In appDelegate.h you have to create an object like this

UITabBarController *Obj_tabbar;

and then in .m file,

-(void) switchToTabbarController    
{    
    Obj_tabbar.delegate = self;
    Obj_tabbar.selectedIndex = 0;
    Tracking_HomeVC *obj = [[Tracking_HomeVC alloc]init];
    [self tabBarController:Obj_tabbar didSelectViewController:obj];
    [self.window addSubview:Obj_tabbar.view];

}

// At this point Tracking_HomeVC is the first view controller of the TabbarController. and it will be added on window.

- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController

{

    if([tabBarController selectedIndex] == 0)
    {
       //Write your code here to do with the first view controller object.
    }

}

and then call it from your LoginView like..

-(void)LoginPressed    
{    
     AppAppDelegate *delegate =(AppAppDelegate *) [[UIApplication sharedApplication] delegate];
     [delegate switchToTabbarController];    
}
Hardik Shah
  • 1,683
  • 1
  • 11
  • 20
  • i have done like what u have said, but when am running the application it is showing an error in delegate.M file like TabBar Controller Un declared(first use in this function). can u tell me whare am doing wrong??? – Karthik Varma Dec 16 '11 at 05:26