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.

Wolfgang



_______________________________________________
Discuss-gnustep mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/discuss-gnustep

Reply via email to