“更多"的徽章价值标签 [英] Badge value on "More" tab
问题描述
我正在制作一个带有tabBarController的iOS应用,该应用带有超过5个选项卡.因此,前四个可以直接单击,其余的位于更多"标签下.
I am making an iOS app which has a tabBarController, with more than 5 tabs. Thus, first four are directly clickable and the rest come under MORE tab.
如果该更多"选项卡中隐藏的选项卡有任何标志,我想在更多"选项卡上显示标志.
I want to show a badge on the MORE tab if there is any badge for the tabs that are hidden inside this MORE tab.
我从但是选项卡的顺序是可配置的.有没有一种方法可以配置更多"选项卡,如果我在其中设置了选项卡的值,它只会放入badgeValue?
But the order of my tabs is configurable. Is there a way I can configure the MORE tab such it just puts the badgeValue if I set a value for a tab inside it?
我正在考虑:
- (void)updateBadgeValue:(NSInteger)count {
int index = [self.tabBarController indexOfObject:self.tabBarItem];
if (index > 4) { //Inside MORE tab
[[[self.tabBarController moreTabBarController] tabBarItem] setBadgeValue:[NSString stringWithFormat:@"%d", count]];
}
//Also setting badge of self.tabbarItem so that it remains when it is brought to "hot tab items".
}
我正在寻找一种解决方案,使我不必为每个选项卡都这样做.另外,如果用户更改了制表符顺序,则badgeValue也应相应更新.
I am looking for a solution such that I dont have to do that for every tab. Also, if the tab order is changed by the user, the badgeValue should also update accordingly.
谢谢.
推荐答案
尝试使用此功能:
- (void)updateBadgeValue:(NSInteger)count {
int index = [self.tabBarController indexOfObject:self.tabBarItem];
if (index > 4) {
int moreTabCount = count + [[[[self.tabBarController moreTabBarController] tabBarItem] badgeValue] intValue];
[[[self.tabBarController moreTabBarController] tabBarItem] setBadgeValue:[NSString stringWithFormat:@"%d", moreTabCount]];
}
}
更新:您可以使用
- (void)tabBarController:(UITabBarController *)tabBarController didEndCustomizingViewControllers:(NSArray *)viewControllers changed:(BOOL)changed
您的 UITabBarController
的委托中的
delegate方法(应为 AppDelegate
).做吧:
delegate method in your UITabBarController
's delegate (it should be AppDelegate
). Let's do it:
- (void)tabBarController:(UITabBarController *)tabBarController didEndCustomizingViewControllers:(NSArray *)viewControllers changed:(BOOL)changed {
if(changed) {
int count = 0;
int i; for(i = 4; i < [viewControllers count]; i++)
count += [[[[viewControllers objectAtIndex:i] tabBarItem] badgeValue] intValue];
if(count > 0)
[[self.tabBarController moreTabBarController] tabBarItem] setBadgeValue:[NSString stringWithFormat:@"%d", count]];
}
}
我认为它将起作用.
这篇关于“更多"的徽章价值标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!