I have an app with a TabBar with 5 tabs (regular tab bar with no custom class). When I start the app the left tab is opened. I want it to open the middle one first. I've tried putting
[self.tabBarController setSelectedIndex:3];
in the ViewDidLoad of the ViewController that is first opened but the tab isn't switching.
I can see it's highlighted but not selected. If I put the code above under viewWillAppear
it will be selected on first run but when I'll select the left tab from time to time it will jump to the middle one.
Also tried this without success:
DetailsViewController* vc = [self.storyboard instantiateViewControllerWithIdentifier:@"DetailsViewController"];
[self.navigationController pushViewController:vc animated:true];
What Am I doing wrong?
This is the only solution that worked for me. in appdelegate:
UITabBarController *tabBar = (UITabBarController *)self.window.rootViewController;
[tabBar setSelectedIndex:2];
In storyboard set custom class to the tabbarController and in that custom class
-(void) viewDidLoad
{
[self.tabBarController setSelectedIndex:3];
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With