ios在AppDelegate中更改了tabbaritem的徽章

时间:2013-12-11 13:34:56

标签: badge

哦!我尝试更改tabbarItemAppDelegate的徽章;然后它确实有效,但tabarItem没有显示!我的代码:

 UIStoryboard *storyBoard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
    UITabBarController *tabBarController = (UITabBarController *)[storyBoard instantiateViewControllerWithIdentifier:@"MainIdentifier"];

    [[tabBarController.tabBar.items objectAtIndex:1] setBadgeValue:[NSString stringWithFormat:@"199"]];

(我也看到网站How to set tabBarItem's badge from AppDelegate.m (tabBarView is not root View)

1 个答案:

答案 0 :(得分:1)

您可以提交原始答案here by Jim Rota

访问标签栏控制器:“

UITabBarController *tabController = (UITabBarController *)self.window.rootViewController;

然后设置徽章

[[tabController.viewControllers objectAtIndex:1] tabBarItem].badgeValue = @"New!";