UITabBarItem 执行 IBAction Xcode 4.2
我希望能够在单击选项卡栏项目时执行 IBaction。我正在使用 Xcode 4.2 具有的默认选项卡栏模板,并且我了解如何将 IB 操作链接到按钮...但是,我尝试将 IBaction 链接到 tabBaritem(位于屏幕底部)时遇到困难。那么,当有人单击我的某个选项卡时,就会执行一项操作?
如何执行此操作?
谢谢!
i want to be able to make an IBaction execute when i click on a tabbar item.. I am using the default tab bar template that Xcode 4.2 has, and i understand how to link an IB Action to a Button... But, i am running into difficulty when trying to link an IBaction to a tabBaritem (at the bottom of the screen). So when someone clicks one of my tabs, an action is executed?
How can this action be performed?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试使用选项卡栏作为工具栏并不是一件好事,有一个 UI 元素可以做到这一点。如果您确实想在单击选项卡栏按钮时运行某个操作,则需要将其添加到由该按钮激活的控制器中。
It's not really a good thing to try and use a tab bar as a toolbar, there is a UI element for that. If you really want to run an action when clicking on a tab bar button, you need to add it to the controller that is activated by the button.
这可以通过将 ViewController 设置为 UITabBarDelegate 然后为每个选项卡栏项目提供一个标签(我将它们标记为 0、1 和 2)来完成。然后实现 UITabBarDelegate 方法,如下所示。只需将“[self PerformTaskXXX]”替换为您需要运行的任何代码即可。
This can be done by setting your ViewController to be a UITabBarDelegate then giving a tag for each of the tab bar items (I tagged them 0, 1 and 2). Then implement the UITabBarDelegate method as shown below. Simply replace "[self performTaskXXX]" with whatever code you need to run.