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.
Asked
Active
Viewed 355 times
1
-
That wouldn't be an intuitive action for the user. – Evan Mulawski Aug 22 '11 at 18:46
-
@Evan Mulawski: it's actually a standard iOS behavior. – jtbandes Aug 22 '11 at 18:51
-
@jtbandes: Really? I have never seen nor used this feature. – Evan Mulawski Aug 22 '11 at 18:53
-
@Evan Mulawski: yep. For example try going to the Phone app, contacts tab, then tap a name to drill down, then tap the contacts tab again. – jtbandes Aug 22 '11 at 18:54
-
@jtbandes: So, does it return the user to the root controller or just go back one? – Evan Mulawski Aug 22 '11 at 18:59
-
Its only one controller with different views inside it. – flopes Aug 22 '11 at 19:01
-
1@Evan Mulawski: it goes back to the root. – jtbandes Aug 22 '11 at 19:03
-
My app have a UITabBarController that call UIViewControllers. This controllers handle a list of views controlled with a UINavigationBar. – flopes Aug 22 '11 at 19:05
3 Answers
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
-
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