0

通知がある場合は、3 つの右バー ボタン アイテムの 1 つである Notifications Button にバッジを設定します。

通知がない場合、通知ボタンは表示されるべきであり、まったく表示されません。通知がある場合、ボタンをバッジ付きの他の 2 つのボタンの中央に表示したいと考えています。潜在的なボタンが2つしかないときに機能しました。ただし、2 つまたは 3 つの右ボタンの左端にあるはずの 3 つ目のボタンを追加しました。バッジは、中央 (通知ボタン) ではなく、右端のボタンに表示されます。

として知られているバッジの挿入を処理するカテゴリを使用しています

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;

}

バッジを右端ではなく中央のボタンに挿入するように指定する方法を誰でも提案できますか?

4

0 に答える 0