0

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!

jo1995
  • 414
  • 1
  • 5
  • 14

2 Answers2

2

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
    }
}
Robert Dresler
  • 10,580
  • 2
  • 22
  • 40
0

You can set value nil in

override func viewDidAppear(_ animated: Bool) {
  if let tabItem = self.tabBarController?.tabBar.selectedItem {
    tabItem.badgeValue = nil
   }
}
Ahmad Abbas
  • 131
  • 13