Re: NSPopupButton fun & games (newbie)
Re: NSPopupButton fun & games (newbie)
- Subject: Re: NSPopupButton fun & games (newbie)
- From: Joannou Ng <email@hidden>
- Date: Tue, 12 Apr 2005 19:16:45 -0400
Hi Duncan,
Try this:
In your nib, instantiate an NSMenu and delete the two default NSMenuItems in it, such that your NSMenu is empty.
>From your app controller class (or whatever), have an outlet to the NSMenu as well as the NSPopUpButton that will contain the NSMenu.
Connect the outlets.
Then, do this in your app controller class (or whatever):
NSMenuItem *menuItem = [[[NSMenuItem alloc] initWithTitle:@"Foo" action:@selector(fooBar:) keyEquivalent:@""] autorelease];
[theMenu addItem:menuItem];
[thePopUp setMenu:theMenu];
I think that should do the trick.
Cheers, Joannou.
On 2005 Apr 12, at 03:38, Duncan Campbell wrote:
Hi folks.
I'm trying to create a popup button, but am having some difficulty.
Just as a test, I tried using the following code:
[[myPopupMenu cell] setUsesItemFromMenu:NO];
NSMenu *mnu = [[NSMenu allocWithZone:[NSMenu menuZone]] initWithTitle:@""];
NSMenuItem *item;
item = [[NSMenuItem allocWithZone:[NSMenu menuZone]] initWithTitle:@"test item1" action:@selector(myMethod:) keyEquivalent:@""];
[item setTag:0];
[mnu addItem:item];
[item release];
item = [[NSMenuItem allocWithZone:[NSMenu menuZone]] initWithTitle:@"test item2" action:@selector(myMethod:) keyEquivalent:@""];
[item setTag:1];
[mnu addItem:item];
[item release];
[myPopupMenu setMenu:mnu];
What happens is that I only get 1 menu item (the 2nd one), and it is disabled.
Can anyone let me know what i'm doing wrong? I took a look at the menu madness demo without too much insight.
Cheers.
---------------------------------------------------------------
Duncan Campbell
http://www.duncanandsarah.com/duncan
---------------------------------------------------------------
... in three to eight years we will have a machine with the general
intelligence of an average human being ... The machine will begin
to educate itself with fantastic speed. In a few months it will be
at genius level and a few months after that its powers will be
incalculable ...
-- Marvin Minsky, LIFE Magazine, November 20, 1970
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden