Use this code:
-(void)newBadge{
_badge++;
[[[[self tabBarController] tabBar] items] objectAtIndex:0] setBadgeValue:[NSString stringWithFormat:@"%d",_badge];
}
objectAtIndex should be the tab bar you want to set.
Question
I've a tabBar controller. Is it possible to set the badge of one viewController by tapping a button in the other view?
for example...
in viewController2
is one method.
-(void)newBadge{
_badge++;
self.navigationController.tabBarItem.badgeValue = [NSString stringWithFormat:@"%d",_badge];
}
Is it now possible to use this method in viewController1
and also display the badge right after tapping the button?
Thanks to all of you in advance.
Solution
Use this code:
-(void)newBadge{
_badge++;
[[[[self tabBarController] tabBar] items] objectAtIndex:0] setBadgeValue:[NSString stringWithFormat:@"%d",_badge];
}
objectAtIndex should be the tab bar you want to set.