• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Adding a new menu programmatically
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Adding a new menu programmatically


  • Subject: Re: Adding a new menu programmatically
  • From: Jason Coco <email@hidden>
  • Date: Tue, 30 Sep 2008 22:48:52 -0400


On Sep 30, 2008, at 16:20 , Matthew Gertner wrote:

Hi,

I'm trying to add a new menu to the main menu of my application using
Cocoa. I thought something like this would do the trick:

NSMenu* menu = [[NSMenu alloc] initWithTitle:@"foo"];
NSMenuItem* item = [[NSApp mainMenu] addItemWithTitle:@"foo"
       action: nil
       keyEquivalent: @""];
[item setSubmenu:menu];

Unfortunately that doesn't seem to do anything at all. I thought that
the top-level menus were actually menu items on the main menu, but
perhaps I am misunderstanding?

This is from the MenuMadness example application included with Xcode and works fine for me:


    NSMenu *newMenu;
    NSMenuItem *newItem;

// Add the submenu
newItem = [[NSMenuItem allocWithZone:[NSMenu menuZone]] initWithTitle:@"Flashy" action:NULL keyEquivalent:@""];
newMenu = [[NSMenu allocWithZone:[NSMenu menuZone]] initWithTitle:@"Flashy"];
[newItem setSubmenu:newMenu];
[newMenu release];
[[NSApp mainMenu] addItem:newItem];
[newItem release];


HTH, Jason

Attachment: smime.p7s
Description: S/MIME cryptographic signature

_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

References: 
 >Adding a new menu programmatically (From: "Matthew Gertner" <email@hidden>)

  • Prev by Date: Re: Adding a new menu programmatically
  • Next by Date: Finding the iTunes Music Library
  • Previous by thread: Re: Adding a new menu programmatically
  • Next by thread: Finding the iTunes Music Library
  • Index(es):
    • Date
    • Thread