1

I am working on a tabbar application with 3 tabs in it.

I have created a UITabBarController with 3 UINavigationController with their respected RootViewControllers which is working perfectly fine.

Now I have a Home button in all of my views. When I click on it suppose to display a HomeView (Which is not the RootViewController of first UINavigationController) with no tabs selected.

Can any one help me with this?

I have tried most of the links related to how to deselect all the tabs of UITabBarController but none of it had the perfect answer..!!

Here is my code:

-(void)setViews
{
   viewController1 = [[FirstViewController alloc] initWithNibName:@"FirstViewController" bundle:nil];
    UIViewController *viewController2 = [[[SecondViewController alloc] initWithNibName:@"SecondViewController" bundle:nil] autorelease];
    UIViewController *viewController3 = [[[ThirdViewController alloc] initWithNibName:@"ThirdViewController" bundle:nil] autorelease];
    viewController4 = [[CalculatorsView alloc] initWithNibName:@"CalculatorsView" bundle:nil];

    navigationController1=[[UINavigationController alloc]initWithRootViewController:viewController1];
    [navigationController1.navigationBar setBackgroundImage:[UIImage imageNamed:@"title-bar.png"] forBarMetrics:UIBarMetricsDefault];
    UINavigationController *navigationController2=[[[UINavigationController alloc]initWithRootViewController:viewController2] autorelease];
    [navigationController2.navigationBar setBackgroundImage:[UIImage imageNamed:@"title-bar.png"] forBarMetrics:UIBarMetricsDefault];
    UINavigationController *navigationController3=[[[UINavigationController alloc]initWithRootViewController:viewController3] autorelease];
    [navigationController3.navigationBar setBackgroundImage:[UIImage imageNamed:@"title-bar.png"] forBarMetrics:UIBarMetricsDefault];
    UINavigationController *navigationController4=[[[UINavigationController alloc]initWithRootViewController:viewController4] autorelease];
    [navigationController4.navigationBar setBackgroundImage:[UIImage imageNamed:@"title-bar.png"] forBarMetrics:UIBarMetricsDefault];

    [navigationController1.navigationBar setHidden:YES];
    [navigationController2.navigationBar setHidden:YES];
    [navigationController3.navigationBar setHidden:YES];
    [navigationController4.navigationBar setHidden:YES];

    self.tabBarController = [[[UITabBarController alloc] init] autorelease];

    self.tabBarController.tabBar.backgroundImage = [UIImage imageNamed:@"tabbar-0.png"];
    [[[self tabBarController]tabBar]setSelectionIndicatorImage:[UIImage imageNamed:@"transparent.png"]];
    [self.tabBarController setDelegate:self];
    self.tabBarController.viewControllers = @[navigationController1, navigationController2,navigationController3];
    appDelegate.window.rootViewController = self.tabBarController;
}

#pragma mark TABBAR DELEGATE

- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController
{
    if (tabBarController.selectedIndex == 0)
    {
        self.tabBarController.tabBar.backgroundImage = [UIImage imageNamed:@"tabbar-1.png"];
        [self.navigationController1 setViewControllers:@ [viewController4] animated:NO];
    }
    else if (tabBarController.selectedIndex == 1)
    {
        self.tabBarController.tabBar.backgroundImage = [UIImage imageNamed:@"tabbar-2.png"];
    }
    else if (tabBarController.selectedIndex == 2)
    {
        self.tabBarController.tabBar.backgroundImage = [UIImage imageNamed:@"tabbar-3.png"];
    }
}

Can any body tell me that its even possible to unselect all tabs?

Ajay
  • 1,622
  • 20
  • 36
  • How can you launch your HomeViewController? – LE SANG Aug 15 '13 at 07:37
  • FirstViewController is my HomeViewController – Ajay Aug 15 '13 at 07:43
  • Click home button -> FirstVC ? You need to use property for all NavigationControllers, reload tabbar anytime click button. change the target of button to AppDelegate – LE SANG Aug 15 '13 at 07:54
  • It will create problem only when I am on HomeViewController-->Navigate by pushing on another view....and Now if I click the first tab the Log says...Finishing up a navigation transition in an unexpected state. Navigation Bar subview tree might get corrupted.Unbalanced calls to begin/end appearance transitions for . – Ajay Aug 15 '13 at 07:58
  • I have used property for all NavigationControllers, and How to reload tabbar? – Ajay Aug 15 '13 at 08:16

0 Answers0