在我的应用程序中,我的 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:
,则那里没有显示徽章。