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.

Était-ce utile?

La 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.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top