我使用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]];
答案 0 :(得分:4)
试一试:
UIViewController *carrinhoVC = [self.tabBarController.viewControllers objectAtIndex:0];
carrinhoVC.tabBarItem.badgeValue = [NSString stringWithFormat:@"%d", 1];
carrinhoVC是你想在TabBar中更新徽章价值的UIViewController。
答案 1 :(得分:1)
此代码对我有用:
private void textBox3_MouseClick(object sender, MouseEventArgs e)
{
//find selected items
Selection sel = uidoc.Selection;
ICollection<ElementId> ids = sel.GetElementIds();
foreach (ElementId id in ids)
{
Element el = doc.GetElement(id);
el.Pinned = true;
}
}