• 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: Dynamic menu building
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Dynamic menu building


  • Subject: Re: Dynamic menu building
  • From: April Gendill <email@hidden>
  • Date: Fri, 15 Aug 2003 10:54:02 -0700

let me break this down then to the simplest question....
I think its getting clear but you'll see by the question I'm going to ask, whether or not I understand.
the submenus I need to create, are treated by cocoa then exactly as any of the items i would add to the mastermenu?
thusly the variable name in the loop means nothing outside the loop and is only a reference used while actually creating that particular submenu and adding items to it.

On Friday, August 15, 2003, at 10:07 AM, Alastair J.Houghton wrote:

Hi April,

I think Joar is right... it looks pretty simple to me; what's wrong with something like

NSMenu *myMainMenu = [[NSMenu alloc] initWithTitle:@"My Menu"];
NSMenu *mySubMenu = [[NSMenu alloc] initWithTitle:@"My Submenu"];

[myMainMenu addItemWithTitle:@"Test" action:NULL keyEquivalent:@""];
[mySubMenu addItemWithTitle:@"Test 2" action:@selector(myMethod:) keyEquivalent:@""];
[[myMainMenu itemAtIndex:0] setSubmenu:mySubMenu];

(OK, it might not work exactly as I just typed it, but something similar should, and it looks pretty simple to me).

If you want to change them on the fly, you just use -removeItemAtIndex or -removeItem to remove any that you don't want, and you can change individual items using the various -setXXX methods on NSMenuItem (e.g. [[myMainMenu itemAtIndex:0] setTitle:@"I just changed title"]).

Don't forget, by the way, that mySubMenu is just a pointer... you can write things like

mySubMenu = [[NSMenu alloc] initWithTitle:@"Foo"];
[[myMainMenu itemWithTag:4] setSubmenu:mySubMenu];

as many times as you like (or even in a loop). People sometimes seem to become confused and think that mySubMenu is their object.

Kind regards,

Alastair.

On Friday, August 15, 2003, at 05:16 pm, April Gendill wrote:

Appearantly you did not understand what I was saying.
I CAN add single items to any menu, the dock menu, any of the main menu bar items. I can add anything ITEM. addItem works fine even if I am pulling data off of a file. HOWEVER to dynamically insert a whole submenu, and to understand what I mean, open safari. In your bookmarks do you have any groups set up? well i do, and with in those groups I have subgroups, so i end up with menus like:
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.

  • Follow-Ups:
    • Re: Dynamic menu building
      • From: Chris Hanson <email@hidden>
    • Re: Dynamic menu building
      • From: j o a r <email@hidden>
References: 
 >Re: Dynamic menu building (From: "Alastair J.Houghton" <email@hidden>)

  • Prev by Date: Re: Help with detecting invalid object when in if() test....
  • Next by Date: Re: Dynamic menu building
  • Previous by thread: Re: Dynamic menu building
  • Next by thread: Re: Dynamic menu building
  • Index(es):
    • Date
    • Thread