View Full Version : Display NSMenuItem When Changed?
Darkroom
Dec 12, 2008, 12:38 PM
i've noticed in some menu bar apps like Google's GMail Notifier, the time since last email check will display when changed while the menu is visible. how can i emulate this behavior in my own NSMenu with a timer that changes?
[MainMenu_Item3 setNeedsDisplay:YES];
doesn't work...
kainjow
Dec 16, 2008, 01:58 PM
I tried to do this a while ago but didn't have much luck, and didn't look into it any further. I have a feeling it's new with Leopard since the AirPort menu does this too. You could try posting the question on cocoadev.com/forums
kainjow
Nov 17, 2009, 07:19 PM
FWIW, for those who come across this in the future:
The main way I found to do this is to use an NSTimer and add it to the run loop with the mode set to NSEventTrackingRunLoopMode. When that timer fires you can update the menu like usual. However, I ran into problems with code that was using the main run loop (e.g. NSURLConnection). It never ran when the menu was active, so instead I created a thread with its own run loop and ran the NSURLConnection there so it would use the thread's run loop. Making sure to rebuild the menu items on the main thread, everything works nicely.
vBulletin® v3.8.6, Copyright ©2000-2012, Jelsoft Enterprises Ltd.