问题
I want to trigger one method when sliding the UISlider is ended.I used "editingDidEnd"event of UISlider in xib and attached it to a IBAction method but the method is not being called.Can any one please help me how to know when sliding is ended on UISlider?
回答1:
UISlider inherits from UIControl so you should be able to add and action on "UIControlEventTouchUpInside"
Try something like :
[slider addTarget:self action:@selector(sliderTouchUpInsideAction:) forControlEvents:UIControlEventTouchUpInside];
Hope this helps, Vincent
回答2:
You can attach to the "UIControlEventValueChanged" slider event instead and use the following code in your event handler:
[slider addTarget:self action:@selector(handleValueChanged:event:) forControlEvents:UIControlEventValueChanged];
- (void)handleValueChanged:(id)sender event:(id)event {
UITouch *touchEvent = [[event allTouches] anyObject]; // there's only one touch
if (touchEvent.phase == UITouchPhaseEnded) { /* place your code here */ }}
来源:https://stackoverflow.com/questions/5855542/uisliders-editingdidend-event-is-not-working-in-ipad