iOS UIStepper not functioning properly
Question
Some simple code:
- (IBAction)Up_Down:(UIStepper *)sender {
double value = [sender value];
[NumDayLabel setText:[NSString stringWithFormat:@"%d", (int)value]];
}
It partially works.
I start it out at five. If I press +, nothing happens. If I press + again, it goes to 6. Then it will continue going up by one each time I press +. Now, if I press + until it reaches 9, then I hit minus, it goes to 10. Then I hit minus again and it goes to 9, then will continue back down so long as I keep pressing minus. If I bring it down to 3, then hit plus, it will go to 2, then start going up so long as I keep pressing +. Hopefully, you get the idea.
Solution
Since you are always one value behind it sounds like you may have added the action for UIControlEventTouchUpInside
. It fires before the stepper value has changed. The correct event for a UIStepper is UIControlEventValueChanged
.