> On 29 Dec 2015, at 7:44 PM, Roland King <r...@rols.org> wrote:
> 
> I can subclass NSSlider or possibly NSSliderCell but that sounds like a whole 
> world of pain, if I have to do that I’ll probably just put a coalescing delay 
> into the whole thing which waits 1/2 second after an update before it 
> actually does the update. 
> 
> Any good ways to do this? 


In your action method, call another method that handles the final value using 
-performSelector:withObject:afterDelay: but just before you do that, call 
+[NSObject cancelPreviousPerformRequestsWithTarget:...] for the same message. 
This schedules a deferred message but immediately cancels it as long as the 
values come pouring in. On the last time, when you stop moving the slider, the 
final -performSelector will get to its target and do its work. The afterDelay 
parameter can be set to whatever value you think you’ll need to allow for a 
slowly moved slider NOT to fire the final message. I typically use 0.1sec.

This mechanism is available to any NSObject, and doesn’t require you to roll 
your own timer-based solution. Behind the scenes this is already doing that.

—Graham



_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to