Working on a tutorial with a NSSlider.
What I want: Moving the slider will show slider value in NSTextField.
Tutorial explains that following method will show slider value in text field:
- (IBAction)sliderDidMove:(id)sender {
NSSlider *slider = sender;
double value = [slider doubleValue];
[sliderValueLabel setDoubleValue:value];
}
Method does not work so I tried to find the method declaration on Apples developer website
but couldn’t find it. From my understanding is the method: sliderDidMove a class method
from the class NSSlider so why I’m unable to find any documentation?
When slider value changes, it sends
-[NSControl action]to its-[NSControl target]. So in Interface Builder you need to Ctrl-drag from the slider to the object that hassliderDidMove:(that will probably be either App Delegate or File’s Owner). The name is chosen by the tutorial’s author, it can be anything else.Alternatively, you can set it up programmatically:
Note also that this particular task is better solved with bindings: bind both slider’s and label’s value to a
doubleproperty of some object, and Cocoa will keep them synchronized.