如何以编程方式确定 iOS 中按下了哪个选项卡按钮?

发布于 2024-08-20 04:44:46 字数 317 浏览 5 评论 0原文

我有一个标签栏,上面有 4 个按钮。当用户按下 A 按钮时我想调用 functionA。当用户按下 B 按钮时我想调用 functionB 等等。

我已经实现了 UITabBarDelegate。

我有这段代码,当按下选项卡栏上的任何按钮时,它会按预期触发。

- (void)tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item

我正在寻找的是一个代码片段,说明如何检测可能使用 item 的委托内部按下了哪个按钮

I have a tabbar with 4 buttons on it. When the user presses the A button 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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

何以畏孤独 2024-08-27 04:44:46

感谢下面 iwat 的评论,我将其编辑得更简单。

以下是 UITabBarController 的委托调用,而不是 UITabBar 本身。

- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController {  
    tabBarController.selectedIndex;
}

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;
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文