NSMenu doesn't start tracking

Posted by Measunny on Stack Overflow See other posts from Stack Overflow or by Measunny
Published on 2010-05-16T11:04:48Z Indexed on 2010/05/16 11:10 UTC
Read the original article Hit count: 354

Filed under:
|
|
|
|

Hey,

I have a little cocoa app which usually operates in the background (as agent). Sometimes I'd like to be able to popup a contextmenu (no window or s.th. visible at this time).

As I'm only targetting Snow Leopard I tried this:

if (windows) {
       NSMenu *theMenu = [[[NSMenu alloc] initWithTitle:@"test"] autorelease];
       [theMenu setShowsStateColumn:NO];
       [theMenu setAutoenablesItems:NO];

           for (id item in windows) {

               NSString *labelText = @"some text";

               NSMenuItem *theMenuItem = [[[NSMenuItem alloc] initWithTitle:labelText
                                             action:@selector(menuItemSelected:)
                                               keyEquivalent:@""] autorelease]; 

               [theMenuItem setTarget:self];
               [theMenuItem setRepresentedObject:item];
               [theMenuItem setEnabled:YES];
               [theMenuItem setImage:icon];
               [theMenu addItem:theMenuItem];
           }

       [theMenu popUpMenuPositioningItem:nil atLocation:[NSEvent mouseLocation] inView:nil];

 }

The menu popsup perfectly but if I hover the items with the mouse cursor they don't highlight and I can't click them.

The menuItemSelected: method looks just like this:

-(IBAction)menuItemSelected:(id)sender {

}

Any idea what I'm doing wrong?

© Stack Overflow or respective owner

Related posts about cocoa

Related posts about nsmenu