Update UITabBarItem badgeValue with More view

╄→尐↘猪︶ㄣ 提交于 2019-12-24 10:40:46

问题


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?


回答1:


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 ...


来源:https://stackoverflow.com/questions/7820421/update-uitabbaritem-badgevalue-with-more-view

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!