16

I have set my UISlider up to respond to value changed events:

[customSlider addTarget:self action:@selector(sliderMove:) forControlEvents:UIControlEventValueChanged];
[customSlider addTarget:self action:@selector(sliderStart:) forControlEvents:UIControlEventTouchDown];
[customSlider addTarget:self action:@selector(sliderEnd:) forControlEvents:UIControlEventTouchUpInside];

I would like to animate the slider to the position where the user left it the last time the view was used. I do this with:

[customSlider setValue:position animated:YES];

Everything works fine, except, I have build a "tag" that hangs over the sliders "knob" so the user can see the value when moving the slider. The position of the "tag" is set when the UIControlEventValueChanged calls the "sliderMove" method.

When using the [slider setValue:position animated:YES] the slider moves, but the event does not fire.

Is there a delegate I can get to or an event that covers this scenario?

Thanks for any help given:)

George Kagan
  • 5,913
  • 8
  • 46
  • 50
RickiG
  • 11,380
  • 13
  • 81
  • 120

1 Answers1

30

Sounds like a bug, try to workaround this by calling

[slider sendActionsForControlEvents:UIControlEventValueChanged];

right after you set the value programmatically.

bddckr
  • 1,393
  • 13
  • 11
  • Hi ChriB and Thanks:) Sending the action manually did force it to respond and behave like it should? I actually didn't think it would call delegate methods during animation. Is there a way to control the speed of the animation, like in UIAnimation, when doing [slider setValue:14 animated:YES], if I may add a question:) – RickiG May 12 '10 at 17:29
  • Don't think there's a way to change that. You should ask this as a new question, maybe someone else knows. :) – bddckr May 12 '10 at 17:39
  • Huh, 11 years later and setValue doesn't trigger the valueChanged action for whatever reason. – cumanzor Sep 19 '21 at 21:21