Skip navigation.
 
mlRe: NSPopupButton fun & games (newbie)
FROM : Joannou Ng
DATE : Wed Apr 13 01:16:45 2005

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

Related mailsAuthorDate
mlNSPopupButton fun & games (newbie) Duncan Campbell Apr 12, 09:38
mlRe: NSPopupButton fun & games (newbie) Joannou Ng Apr 13, 01:16