If you have access to the WWDC site: https://developer.apple.com/wwdc/mac/library/samplecode/CustomMenus/Introduction/Intro.html
If not, then the short answer is that you need to send the action method yourself and then close the menu. Personally, I prefer to wire up the action on the menu item in IB and have my custom view use those. - (void)sendAction { NSMenuItem *actualMenuItem = [self enclosingMenuItem]; // Send the action set on the actualMenuItem to the target set on the actualMenuItem, and make come from the actualMenuItem. [NSApp sendAction:[actualMenuItem action] to:[actualMenuItem target] from:actualMenuItem]; // dismiss the menu being tracked NSMenu *menu = [actualMenuItem menu]; [menu cancelTracking]; [self setNeedsDisplay:YES]; } -raleigh On Aug 29, 2010, at 9:37 PM, Rua Haszard Morris wrote: > Hi Cocoa-dev, > > I'm experimenting with using NSViews in menus, and was expecting that such > items could continue to use Cocoa-provided implementations of mouse tracking, > selecting an item and dismissing the menu, etc. > > After a lot of experimentation, doc reading and googling I've managed to hook > up mouse tracking somewhat correctly - by implementing the delegate method > menu:willHighlightItem:, and ensuring my views get setNeedsDisplay:YES when > they get un-highlighted. This seemed to work correctly but was a lot more > work than I expected. > > More importantly, I want the NSView items to behave the same as other menu > items - i.e. when the user selects one, by mouse or keyboard, the menu > dismisses and actions are sent (and the item highlight flashes briefly). I > can't work out how to get this hooked up without reinventing the wheel. > > Note that my NSViews don't require mouse input - I'm just using NSView items > for custom display, not the more complicated case displaying a control in the > menu. > > Does anyone have any good pointers regarding using NSViews in an NSMenu and > falling back to system-provided code for tracking and selection? > > thanks > Rua HM._______________________________________________ > > 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/ledet%40apple.com > > This email sent to le...@apple.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