使用更多视图更新UITabBarItem badgeValue

时间:2011-10-19 11:11:46

标签: iphone uitabbarcontroller uitabbaritem badge

当我不完全知道TabBarItem的索引时,如何更新它的badgeValue?它可能位于“更多”标签或主标签栏上,具体取决于用户设置的内容..

此外,如果tabbaritem在“更多”内,我只能将一个badgeValue添加到更多项目吗?如何在SDK自动创建的tableview中添加项目本身的徽章?

1 个答案:

答案 0 :(得分:1)

是的,你可以,而且你不必知道索引:

@implementation SomeController
...
-(void)increaseBadgeValue{
    NSString *oldVal = self.tabBarItem.badgeValue;
    self.tabBarItem.badgeValue = [NSString stringWithFormat:@"%d",[oldVal intValue]+1];
}
....
@end

或者,如果您想为另一个控制器执行此操作,请将“self”替换为:

anotherController.tabBar.badgeValue  ....

如果您的应用中有导航控制器,请执行以下操作:

anotherController.NavigationController.tabBarItem.badgeValue ...