[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Question about NSMenuView

From: Wolfgang Lux
Subject: Re: Question about NSMenuView
Date: Mon, 12 Jan 2009 08:09:43 +0100

Germán André Arias Santiago wrote:

NSMenu *menu, *infoMenu;

menu = AUTORELEASE([NSMenu new]);

infoMenu = AUTORELEASE ([NSMenu new]);
[infoMenu addItemWithTitle: @"Info Panel..."
          action: @selector (orderFrontStandardInfoPanel:)
          keyEquivalent: @""];
[infoMenu addItemWithTitle: @"Help..."
          action: @selector (orderFrontHelpPanel:)
          keyEquivalent: @"?"];

NSMenuItem *menuItem;
menuItem = [menu addItemWithTitle: @"Info..." action: NULL
keyEquivalent: @""];
[menu setSubmenu: infoMenu forItem: menuItem] ;

[menu addItemWithTitle: @"Quit" action: @selector (terminate:)
keyEquivalent: @"q"];

[self setMenu: menu] ;
[self setHorizontal: YES] ;

At run the app, I see the menu, but when I do a clic in this the app
crash. If I delete the last two lines, and write [NSApp setMainMenu:
menu], the app work fine. In Mac dev center there isn't information
about this class (in fact is deprecated). Any suggestion?

You've got ownership wrong. A menu owns (and retains) its menu view
and not vice versa. Therefore, you must retain the menu somewhere
else in your code (probably in an attribute of the window's owner).
In addition, you should make the menu view the menu's representation
by replacing the statement [self setMenu: menu]; by
  [menu setMenuRepresentation: self];
Note that this code will not work on Mac OS X, though.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]