Question

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.

Was it helpful?

Solution

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

OTHER TIPS

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.

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!

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