当有通知时,我在通知按钮上设置一个徽章,该按钮是三个可能的右栏按钮项之一。
当没有通知时,“通知”按钮应该也不会显示。当有通知时,我希望按钮显示在其他两个带徽章的按钮中间。当我只有两个潜在的按钮时,它起作用了。但是,我现在添加了第三个按钮,它应该是两个或三个右按钮中最左边的,并且徽章不是出现在我想要的中间位置(通知按钮),而是出现在最右边的按钮上。
我正在使用一个类别来处理插入徽章
UIBarButtonItem+Badge
这是我的代码:
-(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;
}
有谁可以建议如何指定徽章应该插入中间的按钮,而不是最右边的。