开发者

How can I programmatically determine which tab button has been pressed in iOS?

开发者 https://www.devze.com 2022-12-19 12:11 出处:网络
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 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;
}
0

精彩评论

暂无评论...
验证码 换一张
取 消