我正在尝试找到一种方法来使TabBar的项目充当“UI按钮”。 我想按下这个项目只是让它作为一个ibaction方法工作。
我尝试了几个实现:
-(void)tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item{
}
但我无法使该方法有效。
伪造标签栏的项目功能并使其打开例如UIActionSheet的最佳解决方案是什么?
答案 0 :(得分:1)
尝试在viewController中使用IBOutlet和UITabBarDelegate。
@interface MyViewController : UIViewController <UITabBarDelegate> {
IBOutlet UITabBar* tabBar;
}
@end
将UITabBar连接到Interface Builder中的IBOutlet。
在viewController的viewDidLoad方法中将委托设置为“self”:
-(void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
tabBar.delegate = self;
}
并设置委托方法,以区分选项卡:
-(void)tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item
{
NSLog(item.title);
if([item.title isEqualToString:@"some label"]) {
// do something for this specific button
}
}
(这是一篇很老的帖子,但我有同样的问题。希望这能为其他人节省同样的麻烦。)
答案 1 :(得分:0)
您可以尝试使用tabBarController shouldSelectViewController 委托方法。覆盖这个。在要显示ActionSheet的选项卡上返回NO,而是在此方法中实例化ActionSheet。
您需要使用占位符UIViewController来代替此选项卡。
如上所述,这违反Apple HIG,可能是您的应用被拒绝的原因。
答案 2 :(得分:0)
检查一下!这些人创建了一个带有uibutton的tabBar! http://idevrecipes.com/2010/12/16/raised-center-tab-bar-button/
完整源代码: https://github.com/boctor/idev-recipes/tree/master/RaisedCenterTabBar
我前段时间尝试过该代码,它对我有用。
答案 3 :(得分:-1)
在所选标签栏项目视图的viewDidLoad
方法中调用您的操作方法。