2

Is it possible to detect actions that tell my controller when the user is mousing (or otherwise perusing) the items in an NSPopUpButton? I only seem to be notified on a new selection and I'd like to be notified as the user is rolling over any item in the menu.

thanks

tom

TomH
  • 2,950
  • 2
  • 26
  • 49

1 Answers1

2

You could set your controller as the delegate of the NSPopUpButton's menu. You will then be sent -menu:willHighlightItem: delegate messages as the mouse tracks over the menu.

- (void)awakeFromNib
{
    [[popupButton menu] setDelegate:self];
}

- (void)menu:(NSMenu *)menu willHighlightItem:(NSMenuItem *)item
{
    if(menu == [popupButton menu])
    {
        //do something
    }
}
Rob Keniger
  • 45,830
  • 6
  • 101
  • 134
  • I think it'd be better to just test whether they're the same menu (`menu == [popUpButton menu]`). Assuming NSMenu implements a deeper meaning of `isEqual:`, do you really want to perform the action when the user highlights items in an unrelated menu that happens to have “the same” (for some definition of *that*) menu items? – Peter Hosey Jan 27 '10 at 04:42
  • That's a fair point. I've amended the code to use a straight pointer comparison. – Rob Keniger Jan 27 '10 at 06:05
  • Very cool. Thanks very much for taking the time to answer. I'll give this a shot!! – TomH Jan 27 '10 at 16:54