使用更多视图更新UITabBarItem badgeValue [英] Update UITabBarItem badgeValue with More view
问题描述
当我不完全知道TabBarItem的索引时,如何更新它的badgeValue?根据用户的设置,它可能在更多"选项卡或主选项卡上.
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..
如果tabbaritem位于更多"中,我也只能将badgeValue添加到更多"项目中,对吗?如何在由SDK自动创建的表格视图中将徽章添加到项目本身上?
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
或者如果您想为另一个控制器使用它,则将其替换为"self":
Or if you want to do it for another controller, replace 'self' for it:
anotherController.tabBar.badgeValue ....
如果您的应用中有一个NavigationController,请执行以下操作:
if your have a navigationController in your app, do:
anotherController.NavigationController.tabBarItem.badgeValue ...
这篇关于使用更多视图更新UITabBarItem badgeValue的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!