ios - BadgeValue不能在UITabBarItem上更新

标签 ios objective-c ios6 uitabbar uitabbaritem

我使用UITabBarUITabBarItems。在将UITabBarItem分配给tabBarItem之前,我可以为tabBar设置徽章值。但是我的问题是我无法更新tabBarItem的徽章值。

这是我最初可以设置徽章值的代码:

// array of tabBarItems
NSMutableArray * tabs = [[NSMutableArray  alloc] init];

for(iterates few times)
{
    [tabs addObject:[[UITabBarItem alloc] initWithTitle:firstName image:nil tag:i]];
    // set tabItem's property
    [(UITabBarItem *)[tabs objectAtIndex:i] setFinishedSelectedImage:[self convertImage:iconImage toSize:CGSizeMake(iconWidth, TAB_ICON_HEIGHT)] withFinishedUnselectedImage:[self convertImage:iconImage toSize:CGSizeMake(iconWidth, TAB_ICON_HEIGHT)]];
    [[tabs objectAtIndex:0] setBadgeValue:[NSString stringWithFormat:@"%d", 2]];
}
// setting items of UITabBar
[self.chatTabBar setItems:tabs];

在这里,我尝试更新徽章值。因此,发生的是,如果我对新的徽章值NSLog,它会显示更新的值,但UI却看不到变化。
[[self.chatTabBar.items objectAtIndex:0] setBadgeValue:[NSString stringWithFormat:@"%d", 1]];

最佳答案

试试吧:

UIViewController *carrinhoVC = [self.tabBarController.viewControllers objectAtIndex:0];

            carrinhoVC.tabBarItem.badgeValue = [NSString stringWithFormat:@"%d", 1];

carrinhoVC是您要在TabBar中更新徽章值的UIViewController。

关于ios - BadgeValue不能在UITabBarItem上更新,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16397144/

相关文章:

iphone - 当 iPhone 锁定和解锁时,ASIHTTPREQUEST 给出错误 (1)

ios - 使用旧版 SDK 构建的 iOS 静态库

iphone - 更改后退按钮的标题

iOS NSMutablearray 释放行为

objective-c - 如何NSNumber? == nil 在 Objective-C 中在运行时提交?

ios - swift - 向模态视图添加约束

iOS - 将 GIF 从 URL 保存到已保存的相册

ios - 如何从NSArray获取imageUrlString

html - iOS 6 和 iOS 7 中的 UIWebView 渲染差异

ios - 使用__IPHONE_7_0并响应toSelector