Reputation: 414
I want to reset the badge value of the tapItem if the user has seen the notification by visiting the screen.
With this code, I create the badgeValue. but it will never be reset:
func createBadgecount() {
if let tapItems = self.tabBarController?.tabBar.items as NSArray! {
let tapItem = tapItems[3] as! UITabBarItem
tapItem.badgeColor = UIColor.black
tapItem.badgeValue = "\(reports.count)"
}
}
Thanks in advance for your help!
Upvotes: 0
Views: 80
Reputation: 131
You can set value nil in
override func viewDidAppear(_ animated: Bool) {
if let tabItem = self.tabBarController?.tabBar.selectedItem {
tabItem.badgeValue = nil
}
}
Upvotes: 0
Reputation: 11200
You want to set badgeValue
of selectedItem
in tabBar
to nil
if this UIViewController
did appear.
So add this to viewDidAppear
override func viewDidAppear(_ animated: Bool) {
if let tabItem = self.tabBarController?.tabBar.selectedItem {
tabItem.badgeValue = nil
}
}
Upvotes: 2