Update UITabBarItem badgeValue with More view
-
27-10-2019 - |
Question
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?
Solution
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 ...
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow