我使用UITabBar
和UITabBarItems
。在将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/