I am trying to change the badge of the tab bar item but no success. I understood that tab bar controller is responsible of controller the tab bar.
However, some content in the tab bar itself can be managed by the view controller such as the badge
in my code i tried this in view did load
self.tabBarItem.badgeValue = "3"
but nothing appears in the badge
and then I tried :
self.tabBarController?.tabBarItem.badgeValue = "3"
which didn't work neigher, well, i know why the second code didn't work, it is the same as changing the title of a navigation controllre using the navigation controller not the navigation item. but i don't know why the first code didn't work
this is the hiechy of my app, and i am doing so in the TeamsTableViewController which is the first view controller in the teams tab
In your scenario, It is the navigation controller that controls the tabBarItem not the TableViewController, because each TabBarController has an array of viewControllers, and each one of these viewControllers is associated with a tabBarItem. In your case, the tabBarController has two viewControllers, which are:
So the team view navigation controller is the view controller that controllers the tab bar item.
Doing this should solve your problem
self.navigationController?.tabBarItem.badgeValue = "3"
Try this
var cart: UITabBarItem = super.tabBarController.viewControllers[yourIndex].tabBarItem()
cart.badgeValue = "3"
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