-(void)applicationDidFinishLaunching:(UIApplication *)application{
[[[self.window.rootViewController.tabBarController.viewControllers objectAtIndex:1] tabBarItem]setBadgeValue:@"1"];
}
I use storyboard for UI and want to set notifications number for one of the tabbar items, but it seems that I do something wrong.
What is wrong with this code, why I don’t see the notification in the tabbar item?
Thanks in advance.
ANSWER:
FROM APPDELEGATE:
UITabBarController *tabController = self.window.rootViewController;
UIViewController *requiredViewController = [tabController.viewControllers objectAtIndex:1];
UITabBarItem *item = requiredViewController.tabBarItem;
[item setBadgeValue:@"1"];
Why is it all on one line?
Break it down into a few smaller steps, set a breakpoint on step one and walk through the code checking to see if what you expect is happening on each line.
I suspect that one of your properties is
nil– this is usually the cause of ‘why does my method fail without any warning or error` type bugs.