I have used a custom UITabbar for my app Since my app requires a viewcontroller instead of uitabbarcontroller. In that, I have showed both the viewcontroller by adding and removing the 2nd viewcontroller as subview. Till this its fine but the tabbar item not showing the first tabbar item in highlighted state, Instead after selecting the second tabbar item(From this the tabbar items shows the highlight.)the highlighting follows.
So I tried one solution: I have added a bool variable "selected" as User Defined Runtime attribute, this also failed by showing the first tabbar item still highlighted even after the second tabbar is selected.
May I know any other alternative to show the default tab highlight when the view is loaded.
func tabBar(_ tabBar: UITabBar, didSelect item: UITabBarItem){
switch item.tag {
case 1:
if sampleTwo == nil {
var storyboard = UIStoryboard(name: "Main", bundle: nil)
sampleTwo = storyboard.instantiateViewController(withIdentifier: "liveeventsVC") as! LiveEventsViewController
}
sampleTwo?.view.removeFromSuperview()
sampleTwo?.removeFromParentViewController()
break
case 2:
if sampleTwo == nil {
var storyboard = UIStoryboard(name: "Main", bundle: nil)
sampleTwo = storyboard.instantiateViewController(withIdentifier: "liveeventsVC") as! LiveEventsViewController
}
self.view.insertSubview(sampleTwo!.view!, belowSubview: self.bidLiveTabbar)
self.addChildViewController(sampleTwo!)
break
default:
break
}
}
How to show default tab selected while loading the screen that too in custom Tabbar?