1

Is there a way to give an action to a reclick of an UITabBarItem? I want to back to the initial screen of my app when the tab bar item is reclicked. I'm using a UITabBarController with UITabBar and UITabBarItens. My app have a list of views with foward and backward controls. I wish that UITabBarItem act like a home button.

flopes
  • 1,345
  • 1
  • 14
  • 21

3 Answers3

0

This behavior is given to you automatically if you use UINaviationController: when you "reclick" a tab it will pop to the root view controller.

Your other option would be to implement the UITabBarDelegate or UITabBarControllerDelegate protocol and perform an action when the tab is clicked.

jtbandes
  • 115,675
  • 35
  • 233
  • 266
  • I'm using a UITabBarController with UITabBar and UITabBarItens. My app have a list of views with foward and backward controls. I wish that UITabBarItem act like a home button. – flopes Aug 22 '11 at 18:57
  • Consider using UINavigationController inside your tab bar. Otherwise you might have to override some private methods or something to make this work properly. – jtbandes Aug 22 '11 at 18:59
  • @flopes: actually, I think you can do it using delegate methods. See my updated answer. – jtbandes Aug 22 '11 at 19:03
  • Thanks!! The UITabBarControllerDelegate protocol works fine to me. – flopes Aug 22 '11 at 19:50
0

Its default in the UINavigation controller implementation. If you have a UINavigationController and tap an icon in a tab bar, it will pop view controllers until it reaches the root assuming the navigation controller is a child and is one of the tab bar item's controller.

Arvin Am
  • 533
  • 4
  • 11
0

You have to implement a UITabBarControllerDelegate

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

    if (tabBarController.selectedViewController == viewController)
    {
        tabBarController.selectedIndex =0;
    }
}

This should do the trick.

Cheers nettz

nettz
  • 173
  • 2
  • 9