Reputation: 543
Here i am using the 4 tabViews, third one is chat button so here user unread messages how to show the badges
in #import "HomeTabViewController.h"
- (void)viewDidLoad {
[super viewDidLoad];
NSString *badgeVal = @"5";
[[[[self.tabBarController viewControllers] objectAtIndex:2] tabBarItem] setBadgeValue:badgeVal];
}
Upvotes: 1
Views: 436
Reputation: 167
Try this.
NSString *badgeVal = @"5"; //Unread message count
[[self navigationController] tabBarItem].badgeValue = badgeVal;
or
[[self.tabBarController.tabBar.items objectAtIndex:<your item position>] setBadgeValue:[NSString stringWithFormat:@"%d",badgeVal]]
;
Upvotes: 1
Reputation: 10199
Well, just use the badgeValue
property of the UITabbarItem
:
https://developer.apple.com/reference/uikit/uitabbaritem/1617065-badgevalue
Upvotes: 1
Reputation: 72440
You need to simply set badgeValue
property of tabBarItem
for that.
NSString *badgeVal = @"5"; //Unread message count
[[[[self.tabBarController viewControllers] objectAtIndex:2] tabBarItem] setBadgeValue:badgeVal];
Note : I have access 3rd ViewController
using objectAtIndex:2
because you want to set badge for the 3rd UITabBarItem
.
Upvotes: 4