[英]Badge on the tab bar item did not show
在我的應用程序中,我的tabBar項目的badge值在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:
設置徽章值application: didFinishLaunchingWithOptions:
那么那里沒有徽章顯示。
您需要閱讀UIApplicationDelegate協議以及各種狀態轉換。 僅當電話中發生一組狀態更改時,applicationDidBecomeActive過渡不會在啟動時發生。
@Meno謝謝哥們。 它為我工作。
只需復制粘貼
[[tabBarController.tabBar.items objectAtIndex:4] setBadgeValue:@"2"];
在viewDidLoad
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.