简体   繁体   English

TabviewController如何显示未读消息(如徽章)?

[英]TabviewController How to show the unread messages like as badges?

在此处输入图片说明

Here i am using the 4 tabViews, third one is chat button so here user unread messages how to show the badges 在这里我使用的是4个tabViews,第三个是聊天按钮,因此用户未读邮件如何显示徽章

in #import "HomeTabViewController.h" 在#import“ HomeTabViewController.h”中

 - (void)viewDidLoad {
  [super viewDidLoad];
    NSString *badgeVal = @"5";
  [[[[self.tabBarController viewControllers] objectAtIndex:2]  tabBarItem] setBadgeValue:badgeVal];
  }

You need to simply set badgeValue property of tabBarItem for that. 您需要简单的设置badgeValue财产tabBarItem了点。

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 . 注意:我可以使用objectAtIndex:2访问第3个ViewController因为您想为第3个UITabBarItem设置徽章。

Well, just use the badgeValue property of the UITabbarItem : 好吧,只需使用badgeValue属性UITabbarItem

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

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]] ; [[self.tabBarController.tabBar.items objectAtIndex:<your item position>] setBadgeValue:[NSString stringWithFormat:@"%d",badgeVal]] ;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM