is it UITabBarController possible to select the tab in code?like UINavigationController we can use popViewController pop back to rootViewController instead of press the back button, so how can this implement in tabbarcontroller?
Asked
Active
Viewed 2.5k times
1 Answers
76
Use the selectedIndex property on the UITabBarController. More information can be found in the UITabBarController Class Reference.
controller.selectedIndex = 4;
or use
[controller setSelectedIndex:4];

Gerco Dries
- 6,682
- 1
- 26
- 35
-
2that should be [controller setSelectedIndex:4] – Jason Harwig May 21 '09 at 02:58
-
7But that code doesn't trigger tabBarController:didSelectViewController: – gcstr Jun 11 '10 at 00:03
-
If you want to use the delegate method to do work, you could just call it yourself using `self.tabController(tabController, didSelect: controller)`. A bit hacky but it works. You should file a radar for it; setting the index _should_ call it automatically. – barndog Feb 28 '17 at 06:09