Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>It sounds likely that your menu item's action outlet isn't "hooked up" to anything in your code. I don't know from your description whether or not you created the menu in interface builder or are creating it programmatically, but the first thing to do would be to check there. Make sure that if you're creating the menu programmatically, that you've spelled the method name correctly in the @selector() (if you've got warnings that say "[class] may not respond to -Foo" that's a big tip off of a typo).</p> <p>If the connections are looking good, I'd break point the method set as your action and verify that you're actually calling the method you think you are.</p> <p>If you're setting the connections programmatically, breakpoint the addItemWithTitle: (or equivalent call) call and ensure that your NSMenuItem setup correctly immediately after stepping over that line.</p> <p><strong>---EDIT---</strong></p> <p>After looking over the posted code, there are several fundamental flaws with it, any of which could be causing the breakage under 10.6.</p> <ol> <li><p>First, you're confusing the role of a delegate in relation to the menu. The delegate should not be your NSMenu object, your delegate should be an object that is invoked as a "call back" by the NSMenuItem to provide custom logic. You need not be extending NSMenu at all, and your MenuTestAppDelegate should only be extended from NSObject.</p></li> <li><p>The class of your Menu object in your MainMenu.xib file is of type MenuTest, but you don't have a MenuTest class declared in your project. Hopefully this is merely a copy/paste error while you were setting up your test project, but you should check it out.</p></li> <li><p>I find it far easier to set up the NSStatusItem's menu programmatically. Try this:</p></li> </ol> <hr> <pre><code>// create the menu - (void)createMenu { NSMenu* aMenu = [NSMenu new]; [aMenu setDelegate:self]; NSMenuItem* quitItem = [[NSMenuItem alloc] initWithTitle:@"quitItem" action:@selector(quitSelected:) keyEquivalent:@""]; [aMenu addItem:quitItem]; [quitItem release]; NSStatusItem* statusItem = [[NSStatusBar systemStatusBar] statusItemWithLength:NSVariableStatusItemLength]; NSImage* itemImage = [[NSImage alloc] initWithContentsOfFile: [[NSBundle mainBundle] pathForResource:@"image" ofType:@"png"]]; NSImage* itemAlternate = [[NSImage alloc] initWithContentsOfFile: [[NSBundle mainBundle] pathForResource:@"alternate" ofType:@"png"]]; [statusItem setImage:itemImage]; [statusItem setAlternateImage:itemAlternate]; [statusItem setHighlightMode:YES]; [statusItem setMenu:aMenu]; } </code></pre>
 

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