Search code examples
objective-ccocoamacosnsslider

How can I get the value of an NSSlider continuously?


It seems like NSSlider in Cocoa does not provide a delegate to receive an event like Value Changed for a UISlider.

How can I get the value of an NSSlider continuously and display it in an NSTextField, for example?


Solution

  • You need to research Cocoa's Target/Action mechanism. This is a basic Cocoa concept you'll need to understand. The slider (and any other control) can be given a target (some controller object) and an action (the method to call against that controller object).

    The action is fired when the user stops dragging by default. Check the slider's Continuous property in Interface Builder to cause it to trigger the action as you're sliding it.