user717452
user717452

Reputation: 111

Get Current Badge Number of Tab Bar

I have a tab in my app that will have a badge number with it, based off of 3 different actions that occur at 3 different times. I know how to set the tab bar badge using:

[[[[[self tabBarController] tabBar] items]
          objectAtIndex:3] setBadgeValue:[NSString stringWithFormat:@"%d", (int)thetabbadge]];

What I would like to do is take what the current badge number is (0 for nothing, or whatever number may already be on there), and increase it by another NSInteger. Is there a way to read the current badge number property?

Upvotes: 1

Views: 1045

Answers (1)

Lucas van Dongen
Lucas van Dongen

Reputation: 9858

You could use the property badgeValue

Your code looks like it was made five years ago, dotted notation is much easier to read. Also you should try to not do too much in one line.

UITabBarItem *itemToBadge = self.tabBarController.tabBar.items[3];
int currentTabValue = [itemToBadge.badgeValue intValue];
int newTabValue = currentTabValue + 1; // Or whatever you want to calculate
itemToBadge.badgeValue = [NSString stringWithFormat:@"%d", newTabValue];

Upvotes: 4

Related Questions