Iphone 如何使用HomeView中的按钮从uitabcontroller中选择选项卡

Iphone 如何使用HomeView中的按钮从uitabcontroller中选择选项卡,iphone,objective-c,Iphone,Objective C,我的应用程序主视图有5个按钮,我的tabbarcontroller有5个选项卡。所以我需要从每个按钮操作中选择每个选项卡。 提前感谢请执行以下操作: - (IBAction)selectSecondTab:(id)sender { self.tabBarController.selectedIndex = 1; [self.tabBarController.view setNeedsDisplay]; } 这样做: - (IBAction)selectSecondTab:

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

请执行以下操作:

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

这样做:

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

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

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

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

    [self.tabBarController.view setNeedsDisplay]; 
}

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

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

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

    [self.tabBarController.view setNeedsDisplay]; 
}
使用

代替我写下你想要的标签号

使用


代替我写下你想要的标签号

helo…很抱歉它不工作,因为self.tabbar控制器。selectedindex=1表示它在同一个viewcontroller中,但我需要带tabbar视图我需要做一个有5个选项卡的tabbar控制器…同一个选项卡由一个包含5个按钮的窗口驱动…所以主视图是5个按钮,从那时起,当它选择Yes时,它将继续响应tabbar1个选项卡栏控制器和5个选项卡!!!您可以通过写入self.tabBarController.selectedIndex=0来访问每个选项卡,self.tabBarController.selectedIndex=1…我有1个viewcontroller确定我有5个按钮…然后我添加了一个新的uiviewcontroller子类,在xib中我添加了带有5个选项卡的tabBarController…然后从第一个视图访问带有该按钮的选项卡,所以我在该.m文件上写iAction我在mainviewcontroller中写iAction所以self表示它的视图r8?helo…我很抱歉它不工作,因为self.tabbarController.selectedindex=1表示它在同一个viewcontroller中,但我需要带tabbar视图我需要做一个有5个选项卡的tabbar控制器…同一个选项卡由一个窗口驱动,包含5个按钮…因此主视图是5个按钮,从那以后它将转到共同响应tabbar选择是您有1个选项卡栏控制器和5个选项卡!!!您可以通过写入self.tabBarController.selectedIndex=0来访问每个选项卡,self.tabBarController.selectedIndex=1…我有1个viewcontroller确定我有5个按钮…然后我添加了一个新的uiviewcontroller子类,在xib中我添加了带有5个选项卡的tabBarController…然后从第一个视图访问带有该按钮的选项卡,所以我在该.m文件上写iAction我在mainviewcontroller中写iAction所以self是指它的视图r8吗?