4

I have a NSPopupButton that displays a drop down menu when clicked. This menu is populated from an NSArray. Now if I click on one of the items in the drop down Menu, I can select it and determine what is selected etc. What I want to do is when the user clicks on the NSpopupbutton, update the drop down menu and then have the user pick one of the items. I am having trouble finding how to call a IBAction method when I simply select the drop down menu ( not clicking any one item in it). The clicking of an item in the menu results in an IBAction, but I want just the clicking of the down arrow in the NSPopupButton to trigger an action. Any ideas ? Thanks.

cocoacoder
  • 381
  • 8
  • 19

2 Answers2

6

The NSPopupButton sends an NSPopUpButtonWillPopUpNotification when clicked. Have your controller object listen for that notification and respond by updating the dropdown menu.

Gabriel Roth
  • 1,030
  • 1
  • 12
  • 31
3

The accepted answer worked, though now it's called NSPopUpButton.willPopUpNotification

In Swift 4.x, my code looked like:

NotificationCenter.default.addObserver(self,
                 selector: #selector(dropdownMenuOpened),
                 name: NSPopUpButton.willPopUpNotification,
                 object: nil)
sdailey
  • 2,030
  • 2
  • 15
  • 13