BadgeValue没有在UITabBarItem上更新

时间:2013-05-06 10:49:58

标签: 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]];

2 个答案:

答案 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;
        }

    }