Re: NSPopUpButton pullsDown:YES and dummy first item - normal?
Re: NSPopUpButton pullsDown:YES and dummy first item - normal?
- Subject: Re: NSPopUpButton pullsDown:YES and dummy first item - normal?
- From: Michael Ash <email@hidden>
- Date: Thu, 2 Apr 2009 00:46:16 -0400
On Wed, Apr 1, 2009 at 9:55 PM, Rua Haszard Morris
<email@hidden> wrote:
> I am using a pull-down NSPopUpButton for a little button which displays a
> little menu. The menu has some commands in it, i.e. it's not a selection
> menu, the title of the button just displays an icon, no title, no indication
> of a current item from the menu. I am calling (ahem, sending)
> setUsesItemFromMenu:NO on (to) the cell.
>
> It appears that with pull-down menus I need to insert a dummy item at index
> zero as my NSPopUpButton as a placeholder, and that NSPopUpButton/Cell (when
> in pull-down mode) will handily ignore this item.
>
> This seems like a weird hack, and makes me think I'm going about this the
> wrong way - is this a normal approach?
>
> The documentation mentions that the index of the first item in a pull-down
> should be 1, but it doesn't explain that you need to add a dummy item (for
> the zeroth) or else your first item will go missing.
Don't forget to check the conceptual docs:
http://developer.apple.com/documentation/Cocoa/Conceptual/MenuList/Articles/ManagingPopUpItems.html#//apple_ref/doc/uid/20000274
Partway down it says:
"Note that in a pull-down list, the first item is stored at index 1,
not index 0 as is the case with pop-up lists or ordinary menus. This
is done so that the pull-down list’s title can be stored at index 0 if
necessary. Even when the title is stored at index 0, always change the
buttons title with the setTitle: method."
So yes, this is the typical way to do things.
Mike
_______________________________________________
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