Iphone 使用更多视图更新UItabaritem badgeValue

Iphone 使用更多视图更新UItabaritem badgeValue,iphone,uitabbarcontroller,uitabbaritem,badge,Iphone,Uitabbarcontroller,Uitabbaritem,Badge,当我不知道TabBarItem的索引时,如何更新它的值?它可能位于“更多”选项卡或主选项卡栏上,具体取决于用户设置的内容 另外,如果tabbaritem在“More”中,我只能为More项目添加一个badgeValue,对吗?如何在SDK自动创建的tableview中的项目本身上添加徽章?是的,您可以,并且您不必知道索引: @implementation SomeController ... -(void)increaseBadgeValue{ NSString *oldVal = se

当我不知道TabBarItem的索引时,如何更新它的值?它可能位于“更多”选项卡或主选项卡栏上,具体取决于用户设置的内容


另外,如果tabbaritem在“More”中,我只能为More项目添加一个badgeValue,对吗?如何在SDK自动创建的tableview中的项目本身上添加徽章?

是的,您可以,并且您不必知道索引:

@implementation SomeController
...
-(void)increaseBadgeValue{
    NSString *oldVal = self.tabBarItem.badgeValue;
    self.tabBarItem.badgeValue = [NSString stringWithFormat:@"%d",[oldVal intValue]+1];
}
....
@end
或者,如果要为其他控制器执行此操作,请将其替换为“self”:

anotherController.tabBar.badgeValue  ....
如果您的应用程序中有navigationController,请执行以下操作:

anotherController.NavigationController.tabBarItem.badgeValue ...

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

@implementation SomeController
...
-(void)increaseBadgeValue{
    NSString *oldVal = self.tabBarItem.badgeValue;
    self.tabBarItem.badgeValue = [NSString stringWithFormat:@"%d",[oldVal intValue]+1];
}
....
@end
或者,如果要为其他控制器执行此操作,请将其替换为“self”:

anotherController.tabBar.badgeValue  ....
如果您的应用程序中有navigationController,请执行以下操作:

anotherController.NavigationController.tabBarItem.badgeValue ...