I have a UILabel that adds one to its value — basically it counts up — when a button is pressed. Could someone please help me with a minus button? That way if the user accidentally presses the add button more than they needed, they can subtract their mistake. I’ve tried this, but the label’s text is set to -1 now. and I want it to just subtract one each time its pressed:
- (IBAction)subtractButton:(id)sender {
static int integerSaved;
integerSaved = integer;
integerSaved -= 1;
[label2 setText:[NSString stringWithFormat:@"%i", integerSaved]];
}
This code assumes that you are not using Interface Builder, and that you are manually linking “subtract” to the UIButton. If you are using Interface Builder, try this code.
I have not tested this but I think it should work. Good luck!