Thanks, this is just what I was mis-understanding - I thought that an 
NSMenuItem was just a special case of NSMenu, but in fact an NSMenu contains 
NSMenuItems - which, now, seems very straightforward :o)

Hope everyone had a good xmas!

Mikey

On 25 Dec 2009, at 02:59, Paul Bruneau wrote:

> 
> On Dec 24, 2009, at 4:25 AM, Michael Davey wrote:
> 
>> Hi,
>> 
>> I have googled around but have found nothing that can help me with this... I 
>> have a menu in my application that I wish to add sub items to 
>> programatically. I have the Menu itself connected up and I can add 
>> NSMenuItems to it just fine, but seem at a loss to be able to add a sub menu 
>> and the sub itmes to that menu.
>> 
>> I suspect my answer lies in this function:
>> 
>> - (void)setSubmenu:(NSMenu *)aMenu forItem:(NSMenuItem *)anItem
>> 
>> But I do not understand what the forItem part of the method is for. Further, 
>> I can retrieve a menu item from the menu, but am also at a loss as to how to 
>> retrieve my submenu at a stage in the future.  I have a feeling that there 
>> is something very simple that I am not understanding here, and would be very 
>> grateful if someone could point me in the right direction.
>> 
>> And Merry Christmas to everyone!!!
> 
> "anItem" is a pointer to the menu item to which you wish to connect the 
> submenu.
> 
> I was working on code to do this yesterday, and I saw this method, but I 
> preferred instead to just use the -setSubmenu method of my menu items. What 
> you might not be understanding is that you attach a menu to the submenu 
> property of a menu item. You don't add a submenu to a menu as you seem to 
> have put it above.
> 
> In either case, in the future, when you want to get the submenu, you can send 
> the -submenu message to your menu item that has the submenu attached to it in 
> order to retrieve the submenu.
> 
> If you don't know which menu item has a particular submenu that you are 
> interested in, you can search through them, or you could set the tag of the 
> menu item of interest and find the item that has that tag at some later time 
> using NSMenu's  –itemWithTag: method.
> 
> Definitely read the menu programming guide and and NSMenu and NSMenuItem 
> class descriptions and I think you'll find that menus are one of the most 
> straightforward parts of Cocoa to understand.

_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to