Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/mongodb/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone 如何更改TabBarController索引和调用方法_Iphone_Ios4_Uitabbarcontroller - Fatal编程技术网

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

Iphone 如何更改TabBarController索引和调用方法,iphone,ios4,uitabbarcontroller,Iphone,Ios4,Uitabbarcontroller,我在选项卡栏视图的一个控制器中有一个UIButton,我希望该按钮可以更改选项卡栏selectedIndex并调用selectedIndex的控制器方法 例如: 我的按钮在索引3中选择。当用户单击按钮时,我想将selectedIndex更改为0,并在selectedIndex的控制器中调用一个方法 这可能吗?如果是,怎么做 提前谢谢 这是切换到其他选项卡的方式: - (IBAction)buttonPressed:(id)sender { self.tabBarController.s

我在选项卡栏视图的一个控制器中有一个UIButton,我希望该按钮可以更改选项卡栏selectedIndex并调用selectedIndex的控制器方法

例如: 我的按钮在索引3中选择。当用户单击按钮时,我想将selectedIndex更改为0,并在selectedIndex的控制器中调用一个方法

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


提前谢谢

这是切换到其他选项卡的方式:

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

是的,你可以很容易地做到……只需在你的按钮事件方法中使用这个

[self.tabBarController setSelectedIndex:3];

您的意思是在其中一个视图中有一个
ui按钮
,点击该按钮时会选择一个不同的
uitabaritem
(从而改变视图,就像用户点击选项卡栏项目本身一样)?