Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The problem is that when the menu is open, the current run loop mode is not contained in NSRunLoopCommonModes anymore: it becomes NSEventTrackingRunLoopMode.</p> <p>So you have to add your timer to the current run loop for this mode too:</p> <pre><code>// use "scheduledTimer..." to have it already scheduled in NSRunLoopCommonModes, it will fire when the menu is closed menuTimer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(fireMenuUpdate:) userInfo:nil repeats:YES]; // add the timer to the run loop in NSEventTrackingRunLoopMode to have it fired even when menu is open [[NSRunLoop currentRunLoop] addTimer:menuTimer forMode:NSEventTrackingRunLoopMode]; </code></pre> <p>Then in your timed method, when you receive the response to your request, call the method to update the menu on the main thread (the UI thread):</p> <pre><code>[NSURLConnection sendAsynchronousRequest:request queue:[[NSOperationQueue alloc] init] completionHandler:^(NSURLResponse *response, NSData *data, NSError *error) { [self performSelectorOnMainThread:@selector(updateMenu) withObject:nil waitUntilDone:NO modes:[NSArray arrayWithObject:NSRunLoopCommonModes]]; }]; </code></pre> <p>And finally, in your update method, apply the changes to your menu data and don't forget to ask for the menu to update its layout:</p> <pre><code>[menu removeAllItems]; NSDateFormatter *formatter = [[NSDateFormatter alloc] init]; [formatter setDateFormat:@"HH:mm:ss"]; [menu addItemWithTitle:[formatter stringFromDate:[NSDate date]] action:nil keyEquivalent:@""]; [menu update]; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload