Select a tab bar item programmatically (not using UITabBarController) Select a tab bar item programmatically (not using UITabBarController) ios ios

Select a tab bar item programmatically (not using UITabBarController)


[tabBar setSelectedItem: [tabBar.items objectAtIndex:0]];

Which in swift, I think would be:

tabBar.selectedItem = tabBar.items![0] as UITabBarItem


Swift 3:

tabBarController.selectedIndex = 0 // (or any other existing index)


In swift if tabbar is used not tabbarcontroller set default select

var tabbar:UITabBar?//if declare like thistabbar!.selectedItem = self.tabbar!.items![0] as? UITabBarItem

or

let tabbar = UITabBar()//if declare and initilize like thistabbar.selectedItem = self.tabbar.items![0] as? UITabBarItem


matomo