使用标签栏项设置动作-iPhone [英] set up an action with a tab bar item - iphone

查看:95
本文介绍了使用标签栏项设置动作-iPhone的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果可以的话,我不是不可以,但是这种方法可以像对待常规按钮单击(操作)一样处理选项卡栏项目单击吗?原因是:我的应用程序中有一个标签栏,对于大多数标签栏项目,触摸时都不会更改屏幕,但确实会更改视图中显示的数据。似乎为此使用TabBarAppDelegate会有点麻烦...是否有更好的方法?

I don't no if this is possible, but this there a way to treat a tab bar item click like a regular button click(action)? Here's the reason: I have a tab bar in my application, and for most of the tab bar items, I don't change the screen upon a touch, but I do change the data displayed in the view. It seems that it would be going a bit overboard to use a TabBarAppDelegate for this...is there a better way?

谢谢

推荐答案

最直接的方法是UITabBarDelegate。抱歉。通过在类定义之后添加< UITabBarDelegate> 来实现您的类并继承协议,例如:

The most straightforward way is the UITabBarDelegate. Sorry. Implement your class and inherit the protocol by adding <UITabBarDelegate> after your class definition e.g.:

@interface MyViewController : UIViewController<UITabBarDelegate>

然后定义方法 tabBar:didSelectItem:在该类中,例如

and then define the method tabBar:didSelectItem: in that class e.g.

- (void)tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item {
    // Do Stuff!
    // if(item.title == @"First") {...}
}

然后在您的标签栏上设置委托,如下所示: myTabBar.delegate = myClassInstance tabBar:didSelectItem:方法可以在任何位置(包括视图控制器),在该位置您将获得单击按钮的事件。此处更多信息:

Then set the delegate on your tabbar like so: myTabBar.delegate = myClassInstance. The tabBar:didSelectItem: method can be anywhere including your view controller and is where you will get the event that the button was clicked. More info here:

http://developer.apple.com/library/ios/#DOCUMENTATION/UIKit/Reference/UITabBarDelegate_Protocol/Reference/Reference.html

这篇关于使用标签栏项设置动作-iPhone的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆