I'm trying to programatically select/change the tab of the UITabViewController.
I tried doing it via:
self.tabBarController.selectedIndex = 2;
This looks to be the way that I should do it, but it doesn't work. I thought that maybe the self.tabBarController returns a read only object (I sorta remember reading that somewhere), but I'm not sure how to get it to work.
Any help is appreciated!
The site title that appears in the tab bar can be changed from Appearance > Customize > Site Identity.
Set selectedViewController:
self.tabBarController.selectedViewController = viewControllerYouWant;
For example,
self.tabBarController.selectedViewController
= [self.tabBarController.viewControllers objectAtIndex:2];
According to the docs, selectedIndex
or selectedViewController
are the properties you want and are both assignable.
The tabBarController property is readonly, but it returns an object that is editable.
So all your code looks right to me.
This works well for me, if you want to do it by index.
[self.tabBarController setSelectedIndex:2];
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