Hello Graham, and thanks a million. That's exactly where i stand. I don't have a control, only a cell, and I can hardly use the [NSMenu popUpContextMenu] because its visual appearance is different than the desired PopUpButtonCell. My whole situation is 100% programmatic, no IB or NIB or XIB files involved, as I build menus per-request from some cross-platform data containers I get programmatically.
Setting an Action seems the right way for me, because I only need to record somewhere the selected NSMenuItem* --- that's perfectly enough for me, because all other data I need is already attached to the NSMenuItem's "representedObject". One catch though... In my situation, the menus, sub-menus and items are prepared in advance, somewhere-else-in-the-code, where I don't yet know the target and action. These are only available for me when I'm actually activating the menu. Oh yeah I can recursively scan the menu and set up the action and target on each item, just before activating the menu --- but this is SO ugly. I was wondering if there is something on the NSMenu itself I could use to dictate a single target and action for all its menu items? I saw a mysterious "submenuAction" category property accessor --- can it be of use here? What is the purpose of an NSMenu action? Thanks again. I already advanced a lot with your help! On 05/07/2010, at 15:24, Graham Cox wrote: 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 ************************************************************************************ This footnote confirms that this email message has been scanned by PineApp Mail-SeCure for the presence of malicious code, vandals & computer viruses. ************************************************************************************ Motti Shneor ------------------------------------------ Senior Software Engineer Waves Audio ltd. Phone: +972-3-6084155 Mobile: +972-54-4470730 [mailto: mot...@waves.com] _______________________________________________ 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