RE: How to enable menu items for the submenu of NSPopupButton?
RE: How to enable menu items for the submenu of NSPopupButton?
- Subject: RE: How to enable menu items for the submenu of NSPopupButton?
- From: "Chen, Jeff" <email@hidden>
- Date: Fri, 17 Aug 2007 18:07:45 +0800
Ron,
Sorry to make you confused. I'm working on sub menu today. And I met with several problems.
I have tried -indexOfSelectedItem on popup button, but it always returns 0 if I select item from that sub menu.
So do you know the correct method of getting selection from pop up button when sub menu item is selected?
Jeff
-----Original Message-----
From: Ron Fleckner [mailto:email@hidden]
Sent: Friday, August 17, 2007 5:52 PM
To: Chen, Jeff
Cc: Apple cocoa-dev List Cocoa
Subject: Re: How to enable menu items for the submenu of NSPopupButton?
Jeff,
I don't know what your goal is, and I don't know if you can treat the
items of a popup button as if they are the same as the items in a
menu. Perhaps you asked the menu for the -indexOfSelectedItem? That
wouldn't work because NSMenu has no such method. Try asking the
popup button for the selected item index instead.
Ron
On 17/08/2007, at 6:32 PM, Chen, Jeff wrote:
> Hi,
>
> Thank you for your instruction! Now it works.
>
> And do you know how I can get selection from sub menu?
>
> I try to use indexOfSelectedItem, but it always returns 0 if I
> choose item in sub menu.
>
> Best Regards
> Jeff Chen
>
> -----Original Message-----
> From: Ron Fleckner [mailto:email@hidden]
> Sent: Friday, August 17, 2007 4:25 PM
> To: Chen, Jeff
> Cc: Apple cocoa-dev List Cocoa
> Subject: Re: How to enable menu items for the submenu of
> NSPopupButton?
>
>
>> 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
>
> I think you may have forgotten to set the target of each of the
> items. ie, [item1 setTarget:someObject];
>
> Hope that helps,
>
> Ron
_______________________________________________
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