如何将标签栏项目连接到操作?

人气:448 发布:2022-10-16 标签: cocoa-touch interface-builder ios4 uitabbar uitabbaritem

问题描述

我有一个 UIView,它有一个 UITabBar,里面有 4 个 UITabBarItem 组件(都是从 IB 创建的).

I have a UIView which has a UITabBar with 4 UITabBarItem components in it (all created from IB).

我希望当有人点击标签栏中的项目时调用我的 IBAction 函数.但是我无法通过 IB 将 tabbaritem 连接到我的操作...我控制接收到的操作"中的拖动,但它不允许我将它连接到 tabbaritem.

I want my IBAction function called when someone clicks on the items in the tab bar. But I am unable to connect the tabbaritem to my action via IB... I control drag from the "received actions" but it does not allow me to connect that to the tabbaritem.

谢谢德肖恩

推荐答案

你的问题并不清楚你是否还定义了一个 UITabBarController.

It is not clear from your question if you also defined a UITabBarController.

如果你没有(我假设,否则如果你在 IB 中正确定义了东西,点击标签栏项目应该可以工作),要走的路是将 UITabBarDelegate 分配给你的 UITabBar 并定义 tabBar:didSelectItem:

If you did not (as I assume, otherwise clicking on a tab bar item should work if you correctly defined things in IB), the way to go is assigning a UITabBarDelegate to your UITabBar and define tabBar:didSelectItem:

看看 UITabBarDelegate 参考

806