On 05/07/2010, at 9:32 PM, Motti Shneor wrote:

> resultIndex = [popUpButtonCell indexOfSelectedItem]; returns -1 (unknown)
> result = [popUpButtonCell selectedItem]; returns nil!
> 
> How can I resolve this thing? I MUST have popup menus with sub-menus! Is 
> there a hidden member or method that will tell me what was the last selected 
> menu item?


The pop-up menu control doesn't really work with submenus, but if you bypass 
the control and just get each menu item to send an action to a target directly, 
you can do it that way, since the control doesn't actually care that there are 
submenus, it just doesn't deal with them (and for a pulldown, it doesn't matter 
as the button's displayed title doesn't change with the menu selection).

This can also work well if the menu has a delegate that populates the menu 
items, since there's a way to set each menu item's target/action as necessary 
without too much bother (doing that for a complex menu in IB is very tedious).

Another option is to forget using NSPopUpButtonCell and just write your own 
view that implements the button part, and show the menu using + [NSMenu 
(void)popUpContextMenu:(NSMenu *)menu withEvent:(NSEvent *)event 
forView:(NSView *)view];

--Graham




_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to