I have a UILabel
called label
, and you can add or subtract 1 from it using two buttons. When you subtract all the way down to 0, I want the minus button to stop working. And if the value is added, I want the minus button to work again. Here is the method/code I'm using for the add/subtract button:
- (IBAction)addButton1:(id)sender {
[label setText:[NSString stringWithFormat:@"%d",[label.text intValue] +1]];
}
the code is the same for both the add/subtract methods. Except the +1 at the end is a -1.
I tried:
- (IBAction)addButton1:(id)sender {
int val = [label.text intValue];
[label setText:[NSString stringWithFormat:@"%d",[label.text intValue] +1]];
if(val - 1 <= 0) {
UIButton *button = (UIButton *)sender;
[button setEnabled:NO];
}
}