Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Detecting an NSSlider value change

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];
like image 840
Berry Blue Avatar asked Dec 09 '22 08:12

Berry Blue


1 Answers

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.

like image 94
NSGod Avatar answered Dec 11 '22 10:12

NSGod