Search code examples
iosobjective-cnstabviewcontroller

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];
  }

Solution

  • 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.