【问题标题】:IOS Update BadgeValueIOS 更新 BadgeValue
【发布时间】:2012-09-07 09:44:35
【问题描述】:

我正在使用以下代码从我的应用委托中设置徽章

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {    

sleep(2);

    // Set the tab bar controller as the window's root view controller and display.
self.window.rootViewController = self.tabBarController;
[self.window makeKeyAndVisible];

//Count the news pending and show the badge
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *path = [documentsDirectory stringByAppendingPathComponent:@"datatesting.plist"];
NSFileManager *nfm = [[NSFileManager alloc] init];
if([nfm fileExistsAtPath:path])
{        
    // if file exists, get its contents, add more entries
    NSMutableArray *array = [[NSMutableArray alloc] initWithContentsOfFile:path];
    //Get the number of badge you have to show        
    int num;
    num = [array count];
    NSString *numerodeexp = [NSString stringWithFormat:@"%d",[array count]];
    [[[[[self tabBarController] tabBar] items] objectAtIndex:2] setBadgeValue:numerodeexp];

} 
else {
    [[[[[self tabBarController] tabBar] items] objectAtIndex:2] setBadgeValue:@"0"];
}


return YES;
}

我想从我的一个视图控制器更新值,但我无法使用此代码更新它:

    [[[[[self tabBarController] tabBar] items] objectAtIndex:2] setBadgeValue:@"0"];

从 ViewController 更新 Badge 值的最佳方法是什么?

【问题讨论】:

    标签: ios badge


    【解决方案1】:

    使用 tabBarItem:

    [self.tabBarItem setBadgeValue:value];
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-12-10
      • 1970-01-01
      • 2012-09-07
      • 1970-01-01
      • 1970-01-01
      • 2012-08-16
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多