How can I programmatically determine which tab button has been pressed in iOS?
I have a tabbar with 4 buttons on it. When the user presses the A 开发者_如何学Gobutton I want to call functionA. When the user presses the B button I want to call functionB and so on.
I have implemented the UITabBarDelegate.
I have this code and it fires as expected when any button on the tabbar is pressed.
- (void)tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item
What I am looking for is a code snippet that illustrates how to detect which button was pressed inside the delegate presumably using item.
Thanks to iwat's comment below I edited this to be simpler.
The following is a delegate call for the UITabBarController, rather than the UITabBar itself.
- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController {
tabBarController.selectedIndex;
}
精彩评论