select default tab of the tabbarcontroller before opening it when using storyboard and segue

StackOverflow https://stackoverflow.com/questions/23662489

  •  22-07-2023
  •  | 
  •  

質問

In my iOS application I have tabbarviewcontroller that it is not the firt view controller of the app.

Actually it is the second view controller. The first view controller is a dashboard and then by pressing one of the buttons application push the tabbarcontroller to the navigation bar and show the tabbarcontroller(I do all with storyboard)

Based on some situation the default tab that tabbarviewcontroller should show is diffrence. For example, some time I should open the tabbarcontroller so that shows second tab. Some times I should open it so that show first tab. Does somebody know How we can do it? I search the web but do not find any good answer.

役に立ちましたか?

解決

I believe you can set the selectedIndex of the controller. Try [myTabBarController setSelectedIndex:myInt];

If you are using a segue, you should set that in your prepare for segue method. Here's an example.

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    if([segue.identifier isEqualToString:@"myIdentifier"]){  
        [((UITabBarController*)segue.destinationViewController) setSelectedIndex:myInt];
    }
}
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top