如何使用HolmView中的按钮从uitabbarcontroller中选择选项卡

时间:2011-04-29 10:18:11

标签: iphone objective-c

我的应用程序主视图有5个按钮,我有tabbarcontroller和5个标签。所以我需要从每个按钮操作中选择每个标签。 提前致谢

3 个答案:

答案 0 :(得分:2)

做这样的事情:

- (IBAction)selectSecondTab:(id)sender {
     self.tabBarController.selectedIndex = 1; 
    [self.tabBarController.view setNeedsDisplay]; 
}

答案 1 :(得分:1)

使用

self.tabBarController.selectedIndex = i; 

而不是我写下你想要的标签数量!!!

答案 2 :(得分:0)

为视图中的每个按钮指定标签为0,1,2,3,4,并对所有按钮使用相同的操作

- (IBAction)selectTab:(id)sender 
{
    UIButton *button = (UIButton*)sender;

    [self.tabBarController setSelectedIndex:[button tag]]; 

    [self.tabBarController.view setNeedsDisplay]; 
}