Siva Sankar
Siva Sankar

Reputation: 543

TabviewController How to show the unread messages like as badges?

enter image description here

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

Answers (3)

Keyur Akbari
Keyur Akbari

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

Andreas Oetjen
Andreas Oetjen

Reputation: 10199

Well, just use the badgeValue property of the UITabbarItem:

https://developer.apple.com/reference/uikit/uitabbaritem/1617065-badgevalue

Upvotes: 1

Nirav D
Nirav D

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

Related Questions