2011-04-02 27 views
2

我有一个UButton在我的一个tabBar视图的控制器中,我希望该按钮可以更改tabBar selectedIndex并调用selectedIndex的控制器方法。如何更改TabBarController索引和调用方法

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

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

提前致谢!

+0

你的意思是你在其中一个视图中有一个'UIButton',当点击时会选择一个不同的'UITabBarItem'(从而改变视图,就好像用户敲击标签栏项目本身一样)? – antalkerekes 2011-04-02 04:02:21

+0

是的,就是这样。抱歉。 – 2011-04-02 04:12:41

回答

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]; 
} 
2

雅,你可以很容易地做到这一点....只是使用在您的按钮事件方法

[self.tabBarController setSelectedIndex:3];