Message: 17
Date: Fri, 17 Aug 2007 11:57:34 +0800
From: "Chen, Jeff" <email@hidden>
Subject: How to enable menu items for the submenu of NSPopupButton?
To: "email@hidden" <email@hidden>
Cc: "Yu, Min" <email@hidden>, "Gu, Kevin"
<email@hidden>
Message-ID: <20070817115734026.00000001652@chnxcs325>
Content-Type: text/plain; charset=gb2312
Hi All,
I've met with a issue about menuitem of sub menu:
I create a NSPopupButton, and I want to add sub menu to the 3rd
menu item, but in the added sub menu all menu items are disabled.
My sample code is as following:
NSMenu* menu = [(NSPopUpButton*)ControlPtr menu]; // get the menu
of NSPopupButton
NSMenu* subMenu = [[[NSMenu alloc] init] autorelease]; // create
sub menu
NSMenuItem * item1 = [[[NSMenuItem alloc] initWithTitle:@"Item1"
action:NULL keyEquivalent:@""] autorelease];
[subMenu addItem:item1];
NSMenuItem * item2 = [[[NSMenuItem alloc] initWithTitle:@"Item2"
action:NULL keyEquivalent:@""] autorelease];
[subMenu addItem:item2];
NSMenuItem * item3 = [[[NSMenuItem alloc] initWithTitle:@"Item3"
action:NULL keyEquivalent:@""] autorelease];
[subMenu addItem:item3];
[[subMenu itemAtIndex:0] setRepresentedObject:@"Item1"];
[[subMenu itemAtIndex:1] setRepresentedObject:@"Item2"];
[[subMenu itemAtIndex:2] setRepresentedObject:@"Item3"];
NSMenuItem * mainItem = [menu itemAtIndex:2];
[mainItem setSubmenu:subMenu];// set sub menu
However, in subMenu, all items(item1, item2, item3) are disabled.
Anyone knows how to resolve such issue?
Best Regards
Jeff Chen