• 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: How to enable menu items for the submenu of NSPopupButton?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How to enable menu items for the submenu of NSPopupButton?


  • Subject: Re: How to enable menu items for the submenu of NSPopupButton?
  • From: Ron Fleckner <email@hidden>
  • Date: Fri, 17 Aug 2007 19:51:49 +1000

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


  • Follow-Ups:
    • RE: How to enable menu items for the submenu of NSPopupButton?
      • From: "Chen, Jeff" <email@hidden>
References: 
 >RE: How to enable menu items for the submenu of NSPopupButton? (From: "Chen, Jeff" <email@hidden>)

  • Prev by Date: Elango C has added you as a friend on YouMint.
  • Next by Date: RE: How to enable menu items for the submenu of NSPopupButton?
  • Previous by thread: RE: How to enable menu items for the submenu of NSPopupButton?
  • Next by thread: RE: How to enable menu items for the submenu of NSPopupButton?
  • Index(es):
    • Date
    • Thread