繁体   English   中英

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

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

在此处输入图片说明

在这里我使用的是4个tabViews,第三个是聊天按钮,因此用户未读邮件如何显示徽章

在#import“ HomeTabViewController.h”中

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

您需要简单的设置badgeValue财产tabBarItem了点。

NSString *badgeVal = @"5"; //Unread message count
[[[[self.tabBarController viewControllers] objectAtIndex:2] tabBarItem] setBadgeValue:badgeVal];

注意:我可以使用objectAtIndex:2访问第3个ViewController因为您想为第3个UITabBarItem设置徽章。

好吧,只需使用badgeValue属性UITabbarItem

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

尝试这个。

NSString *badgeVal = @"5"; //Unread message count
[[self navigationController] tabBarItem].badgeValue = 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