1、self.tabBarController setSelectedIndex的使用位置:
在TabBar app中,切换到tabBarItem。
假设你有两个tabbaritem,第一个关联到FirstViewController,第二个关联到SecondViewController,现在我们要却换到第二个SecondViewController下面。
在ImFirstViewController.m中加入代码:
- (void) viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
//在这里设置需要切换到的Index,现在我们却换到index为1的viewcontroller下。
[self.tabBarController setSelectedIndex:1];
}
当然,你也可以在view显示之后加入以上代码。但是加在viewWillAppear之前,可能会不起作用。