【问题标题】:Update UITabBarItem badgeValue with More view使用更多视图更新 UITabBarItem badgeValue
【发布时间】:2011-12-10 20:22:35
【问题描述】:

当我不完全知道 TabBarItem 的索引时,如何更新它的 badgeValue?它可能位于“更多”选项卡或主选项卡栏上,具体取决于用户设置。

此外,如果 tabbaritem 在“更多”内,我只能将 badgeValue 添加到“更多”项目,对吗?如何在 SDK 自动创建的 tableview 中为 item 本身添加徽章?

【问题讨论】:

    标签: iphone uitabbarcontroller uitabbaritem badge


    【解决方案1】:

    是的,你可以,而且你不必知道索引:

    @implementation SomeController
    ...
    -(void)increaseBadgeValue{
        NSString *oldVal = self.tabBarItem.badgeValue;
        self.tabBarItem.badgeValue = [NSString stringWithFormat:@"%d",[oldVal intValue]+1];
    }
    ....
    @end
    

    或者,如果您想为另一个控制器执行此操作,请将 'self' 替换为它:

    anotherController.tabBar.badgeValue  ....
    

    如果您的应用中有一个 navigationController,请执行以下操作:

    anotherController.NavigationController.tabBarItem.badgeValue ...
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多