Changing the range value of the range slider
I have a UIControl range slider class. When dragging, a method is called for each value report
. I want the method to be report
called once when the user finishes dragging. I am stuck with this code, please help.
[slider addTarget:self action:@selector(report:) forControlEvents:UIControlEventValueChanged];
For more information WebService Call Slider Range
source to share
UISlider
has a property continuous
. Set it to NO
and you only get a callback when the user lifts their finger. From the documentation :
If
YES
, the slider continuously broadcasts update events to the appropriate associated target actions. IfNO
, the slider only dispatches an action event when the user releases the thumb of the slider to set the final value.The default value for this property is
YES
.
source to share
So, as you pointed out below yourself (in a very short "answer" :)), you can catch the event UIControlEventTouchUpInside
that is dispatched in the touchhesEnded method of your control:
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
[super touchesEnded:touches withEvent:event];
[self sendActionsForControlEvents:UIControlEventTouchUpInside];
trackingSlider = nil; //we are no longer tracking either slider
}
So you can change
[slider addTarget:self action:@selector(report:) forControlEvents:UIControlEventValueChanged];
to
[slider addTarget:self action:@selector(report:) forControlEvents:UIControlEventTouchUpInside];
I haven't tested it, but I think it should be the way to go ...
EDIT:
Meanwhile, I tested it and that's the way to go. It would be nice to get some hints for the correct answers, I can't wait to finally be able to comment on other people's answers :)
source to share