I have a view derived from UIViewControler (not UITabBarController). In this view I added a tab bar with several tab bar items. I used the UITabBarDelegate to allow the view to do something when users tap on each tab bar item.
class MyViewController: UIViewController, UITabBarDelegate {
func tabBar(tabBar: UITabBar, didSelectItem item: UITabBarItem!) {
// do something
}
}
My question is how we can programmatically select the first tab bar item when the view is first loaded? Note that I would want the first tab item to be in "active" state also.
Again, I'm not using UITabBarController
Thanks
Which in swift, I think would be:
if you inside UITabBarController you can use
self.selectedIndex = // set target index
In swift if tabbar is used not tabbarcontroller set default select
or
In Xamarin.ios, we can use like this mainTabBarController.selectedIndex=3;
Swift 3:
Before select active tab bar item on viewDidLoad event
[self.tabBar setSelectedItem: [self.tabBar.items objectAtIndex:0]];