How can I update the badgeValue of a TabBarItem when I do not exactly know the index of it? It might be in the "More" tab or on the main Tabbar depending on what the user sets..

Also if the tabbaritem is inside "More" I can only add a badgeValue to the More item right? How can I add the badge on the item itself in the tableview which is created automatically by the SDK?

有帮助吗?

解决方案

Yes you can, and you don't have to know index:

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

Or if you want to do it for another controller, replace 'self' for it:

anotherController.tabBar.badgeValue  ....

if your have a navigationController in your app, do:

anotherController.NavigationController.tabBarItem.badgeValue ...
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top