0

When there are notifications, I set a badge on a Notifications Button that is one of three potential Right bar button items.

When there are no notifications, the notifications button should and does not show at all. When there are notifications, I want the button to show in the middle of the two other buttons with the badge. It worked when I only had two potential buttons. However, I have now added a third button which is supposed to be the leftmost of two or three right buttons and the badge is appearing not where I want it on the middle (notifications button) but on the right-most button.

I am using a category that handles inserting the badge known as

UIBarButtonItem+Badge

Here is my code:

-(void) updateNotificationsButton {
    NSMutableArray *buttonsToShow;
    NSInteger badgeInt =[[NSUserDefaults standardUserDefaults] integerForKey:@"badgeInt"];
     if (badgeInt>=1) {
        buttonsToShow = [NSMutableArray arrayWithObjects:myBarButton,notificationButton,searchButton, nil];
    } else {
         buttonsToShow = [NSMutableArray arrayWithObjects:myBarButton, searchButton,nil];    }
   [self.navigationItem setRightBarButtonItems:buttonsToShow animated:YES];
   NSString *onebadgestring= [NSString stringWithFormat: @"%li",badgeInt];
    NSString *badgestring = [@(badgeInt) stringValue];

    self.navigationItem.rightBarButtonItem.badgeValue = badgestring;

}

Can anyone suggest how to specify that the badge should be inserted on the middle button, not the rightmost.

user1904273
  • 4,562
  • 11
  • 45
  • 96

0 Answers0