【问题标题】:Get Current Badge Number of Tab Bar获取标签栏的当前徽章编号
【发布时间】:2014-08-16 11:31:05
【问题描述】:

我的应用中有一个标签,上面有一个徽章编号,基于在 3 个不同时间发生的 3 个不同操作。我知道如何设置标签栏徽章使用:

[[[[[self tabBarController] tabBar] items]
          objectAtIndex:3] setBadgeValue:[NSString stringWithFormat:@"%d", (int)thetabbadge]];

我想要做的是获取当前的徽章编号(0 代表什么都没有,或者那里可能已经存在任何数字),并将其增加另一个 NSInteger。有没有办法读取当前的徽章编号属性?

【问题讨论】:

    标签: ios uitabbarcontroller badge


    【解决方案1】:

    您可以使用属性badgeValue

    您的代码看起来像是五年前编写的,点符号更容易阅读。另外,你应该尽量不要在一行中做太多。

    UITabBarItem *itemToBadge = self.tabBarController.tabBar.items[3];
    int currentTabValue = [itemToBadge.badgeValue intValue];
    int newTabValue = currentTabValue + 1; // Or whatever you want to calculate
    itemToBadge.badgeValue = [NSString stringWithFormat:@"%d", newTabValue];
    

    【讨论】:

      猜你喜欢
      • 2018-10-31
      • 1970-01-01
      • 2011-05-21
      • 1970-01-01
      • 2017-08-23
      • 1970-01-01
      • 1970-01-01
      • 2012-07-22
      • 1970-01-01
      相关资源
      最近更新 更多