ios change the tabbaritem's badge in the AppDelegate

2k Views Asked by At

oh! i try to change the badge of tabbarItem in the AppDelegate;then it do work, but the tabarItem doesn't show! my code :

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

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

(i also see the site How to set tabBarItem's badge from AppDelegate.m (tabBarView is not root View))

1

There are 1 best solutions below

0
On

You can upvote the original answer here by Jim Rota

Access Tab Bar Controller:"

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

Then set the badge

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