Michael Michael - 1 year ago 76
Objective-C Question

What gets called when a UISlider value changes?

Does a method get called when a

changes? I want to be able to update a value based on the
value, but only when it changes...

Thanks for any help.

Answer Source

In IB, you can hook up an IBAction to the Value Changed event or in code add target/action for UIControlEventValueChanged. For example:

[mySlider addTarget:self action:@selector(sliderValueChanged:) forControlEvents:UIControlEventValueChanged];

- (IBAction)sliderValueChanged:(UISlider *)sender {
    NSLog(@"slider value = %f", sender.value);

Note that if you want the value change events as the user is sliding, then be sure that the slider's continuous property is also set. On the other hand, if you don't want the event to fire as the user is sliding and only when they finish sliding, set continuous to NO (or uncheck in IB).

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download