Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Bunkum

macrumors newbie
Original poster
Jun 4, 2010
11
0
In my application when I click and hold down on a NSButton it stops the NSTimer loop that calls my drawRect. And I'm wondering why that is so, and how to prevent it.

I tried making my own subclass of NSButtonCell and overriding trackMouse:inRect:eek:fView:untilMouseUp: and the other subsequent tracking method associated with it. But that didn't help, though I still assume there's something in there I can do to prevent this.

I also tried running OpenGL on another thread but it still seems to get blocked when I hold down the button.
 
Last edited:
Do this:

  • subclass NSButton
  • Override -mouseDown:, -mouseDragged: and -mouseUp:
  • Do not call super in any of those overrides, except perhaps to do highlighting/unhighlighting (even the, self would be fine)
  • In -mouseDown:, handle the click, then leave (do not wait for mouse-up, handle the tracking asynchronously through the other methods)

This should hand control over to the main runloop more often so that your UI can update as required.
 
It sounds like NSButton (or NSButtonCell) is shifting the NSRunLoop into a different mode while it tracks the mouse.

I'm assuming you're using either scheduledTimerWithTimeInterval:target:selector:userInfo:repeats: or scheduledTimerWithTimeInterval:invocation:repeats: to create your timer. These methods will only add the timer to the default run-loop mode.

Instead try using timerWithTimeInterval:target:selector:userInfo:repeats: or timerWithTimeInterval:invocation:repeats:, and then manually adding the timer to the run loop for the common mode.

Code:
[[NSRunLoop mainRunLoop] 
    addTimer:timer 
     forMode:NSRunLoopCommonModes];
 
Thanks you two, I had just worked it out when I checked the thread just now to update it. It was as you said jiminaus I was creating my timer using scheduledTimerWithTimeInterval:target:selector:userInfo:repeats: on my main thread. But I solved it by just creating another thread and creating the timer from there, but I'm going to checkout your solution cause it might be more appropriate.


Just tested it and adding it to the common mode works perfectly, thanks again.
 
Last edited:
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.