Hari Narayanan Hari Narayanan - 21 days ago 5
Objective-C Question

How to set Tab bar item badgeValue in objective c?

Actually I have one custom

TabBarController
and I need to set badgeValue for separate
tabbaritem
at initially that custom tabar loaded with that index path of the tab bar item.

[[self navigationController] tabBarItem].badgeValue = @"3";


I used above code for that
UIViewcontroller
but it shows only when I click on the tab bar item.

and I have also tried the below code in
custom tabBarController
but it didn't working.

[[self.tabBarController.tabBar.items objectAtIndex:3] setBadgeValue:@"2"];


I need to display the badge value at initial.

Answer

If you want to set badge number when you show first tab of your tabbarcontroller then set

  [[self.tabBarController.tabBar.items objectAtIndex:3] setBadgeValue:@"2"];

in viewdidload of your first tab, means first viewcontroller of your tabbbarcontroller