Question

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.

Was it helpful?

Solution

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];
    }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top