Re: Dynamic menu building
Re: Dynamic menu building
- Subject: Re: Dynamic menu building
- From: "Alastair J.Houghton" <email@hidden>
- Date: Fri, 15 Aug 2003 18:07:53 +0100
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.