在我的應用程序,我的TabBar項目的徽章值被設置在AppDelegate.m
,如下:徽章標籤欄項目沒有顯示
AppDelegate.m
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
...
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
UITabBarController *tabBarController = [storyboard instantiateViewControllerWithIdentifier:@"tabBarController"];
[[tabBarController.tabBar.items objectAtIndex:4] setBadgeValue:@"1"];
...
}
- (void)applicationWillEnterForeground:(UIApplication *)application
{
...
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
UITabBarController *tabBarController = [storyboard instantiateViewControllerWithIdentifier:@"tabBarController"];
[[tabBarController.tabBar.items objectAtIndex:4] setBadgeValue:@"2"];
...
}
- (void)applicationDidBecomeActive:(UIApplication *)application
{
...
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
UITabBarController *tabBarController = [storyboard instantiateViewControllerWithIdentifier:@"tabBarController"];
[[tabBarController.tabBar.items objectAtIndex:4] setBadgeValue:@"3"];
...
}
問題是:徽章值始終爲「1」。爲什麼在applicationWillEnterForeground:
和applicationDidBecomeActive:
中設置的徽章值永遠不會出現?如果我沒有在application: didFinishLaunchingWithOptions:
中設置徽章值,那裏沒有顯示徽章。
嘗試將其設置在viewDidLoad – 2012-07-24 10:38:12
我現在有同樣的問題。我將徽章值設置爲applicationDidBecomeActive。我可以在調試中看到正確的值,但是當我的標籤欄可視化時,我失去了徽章值! 爲什麼?有解決方案嗎? – Blasco73 2013-12-21 09:13:58
@ Blasco73 Plz檢查他人的答案和回覆:) – 2013-12-21 09:27:12