如何更改TabBarController索引和调用方法

时间:2011-04-02 03:50:42

标签: iphone ios4 uitabbarcontroller

我的tabBar视图控制器中有一个UIButton,我希望该按钮更改tabBar selectedIndex并调用selectedIndex的控制器方法。

实施例: 我的按钮是selectedIndex 3.当用户单击按钮时,我想将selectedIndex更改为0并在该selectedIndex的控制器中调用方法。

这可能吗?如果是这样,怎么样?

提前致谢!

2 个答案:

答案 0 :(得分:2)

这是您可以切换到其他标签的方法:

- (IBAction)buttonPressed:(id)sender 
{
    self.tabBarController.selectedIndex = 0;

    /* Running method declared in FirstViewController */

    FirstViewController *firstView = [[FirstViewController alloc] init];

    // call methods here
    [firstView methodName];    

    [firstView release];
}

答案 1 :(得分:2)

呀,你可以轻松地做到这一点....只需在按钮事件方法中使用它

[self.tabBarController setSelectedIndex:3];