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.

有帮助吗?

解决方案

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.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top