Is there a way to give an action to a reclick of an UITabBarItem? I want to back开发者_StackOverflow 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.
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.
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.
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
精彩评论