NSTimer with a menu application

I am working on a simple timer application, and I created an NSStatusItem with a menu, and I have some NSTextField labels that update timer labels ( http://cld.ly/e81dqm ), but when I click on the status item, NSTimer stops (and stops updating labels) ..... how can I get around this problem?

EDIT: here is the code that starts the timer:

timer = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(timerDidUpdate:) userInfo:nil repeats:YES];

+7
objective-c cocoa nstimer
source share
2 answers

I assume the timer will resume as soon as you stop interacting with NSStatusItem? (After the menu is disabled and the mouse button is released).

Interaction with the user puts the main startup cycle in the mode when he does not update the timers, so if your shortcut needs to be constantly updated, you probably need to move NSTimer and the label drawing to a separate process or another thread.

+4
source share

You must add a timer to MainRunLoop as follows:

 NSRunLoop * rl = [NSRunLoop mainRunLoop]; [rl addTimer:timer forMode:NSRunLoopCommonModes]; 
+11
source share

All Articles