4

How do I wire up an action programmatically to my NSSlider to detect when the value changes?

I'm looking for the Cocoa equivalent of a UISlider that would be done with the following code.

[myUISlider addTarget:self action:@selector(valueChanged:) forControlEvents:UIControlEventValueChanged];
Berry Blue
  • 15,330
  • 18
  • 62
  • 113

2 Answers2

13

You'd use the following code:

[slider setTarget:self];
[slider setAction:@selector(valueChanged:)];

That's it.

NSSlider uses an NSSliderCell, which is a custom subclass of NSActionCell; I'd look over that documentation for the target action mechanism in Cocoa.

NSGod
  • 22,699
  • 3
  • 58
  • 66
1
[slider setTarget:self];
[slider setContinuous:YES];
[slider setAction:@selector(valueChanged:)];

-(void)valueChanged:(NSSlider *)sender{ 

}
koen
  • 5,383
  • 7
  • 50
  • 89