0

I have a barButton badge. I want to display an integer in it.

@property (nonatomic) int section;
@synthesize section;

-(void)sendBadgeIntBack:(int)section
{
    self.section = section;
    NSLog(@"The numbers of sections in tableView are: %i", self.section);
}

    NSString *strValue = [@(section) stringValue];

    BBBadgeBarButtonItem *barButton = [[BBBadgeBarButtonItem alloc] initWithCustomUIButton:customButton];
    barButton.badgeValue = strValue;

In the NSLog I get a correct value.

I've also tried some other ways:

NSString *strValue = [NSString stringWithFormat:@"%d", section];
NSString *strValue = [NSString stringWithFormat:@"%i", section];
barButton.badgeValue = [NSString stringWithFormat:@"%d", section]; 

Is there a reason why it doesn't work?


Edit:

    UIButton *customButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 20, 20)];

    [customButton addTarget:self action:@selector(barButtonItemPressed:) forControlEvents:UIControlEventTouchUpInside];

    [customButton setImage:[UIImage imageNamed:@"afvaldag"] forState:UIControlStateNormal];
SwingerDinger
  • 276
  • 1
  • 7
  • 21
  • What's `customButton`? Could it be the reason it fails? Also, BBBadgeBarButtonItem seems to be a custom class. What's the source? – Larme Jun 24 '14 at 13:26
  • Custom Button is a UIButton. See update. Second, the source is from here: https://github.com/TanguyAladenise/BBBadgeBarButtonItem – SwingerDinger Jun 24 '14 at 14:41
  • What do you have if you log `badgeButton.badgeValue`? When do you set `badgeButton`? – Larme Jun 24 '14 at 14:50
  • When I log the badgeButton.badgeValue I get 0. I set the badgeButton in ViewDidLoad. – SwingerDinger Jun 24 '14 at 15:42
  • And what value should you have? What value has `section` at that time? It's unclear when you create `badgeButton`, when is called `sendBadgeIntBack:`. – Larme Jun 24 '14 at 15:44
  • I get the `integer` from an other ViewController. I find it weird that I get an result that is right in the `(void)`, but when I convert it into a string I get no right result – SwingerDinger Jun 24 '14 at 15:46
  • It should be 6, because thats the amount of sectionsInTableView. – SwingerDinger Jun 24 '14 at 15:48
  • 1
    Try to log `section` before trying to convert it in a `NSString`. I think that you have an issue with your architecture. – Larme Jun 24 '14 at 15:54
  • It does work Larme. I tried the log in the viewDidLoad and viewDidAppear and it gives me the right outcome. – SwingerDinger Jun 24 '14 at 15:59
  • Nvm! It works! :D I had to put everything (all code in the question) in `ViewDidAppear`. – SwingerDinger Jun 24 '14 at 16:05

0 Answers0