swiftmacosnotificationsnspopupbutton

osx NSPopUpButton Notification after Selection


I need to know the user selection after the user changed the item from a NSPopUpButton.

Why on earth does the NSPopUpButton control has a notification before the user action.:

Posted when an NSPopUpButton object receives a mouse-down event—that is, when the user is about to select an item from the menu.

Implementing the NSPopUpButton notification works fine:

@objc func popUpButtonUsed(notification: NSNotification){
    print(distributionPopUpButton.titleOfSelectedItem!)
}

But how can I trigger an action/method after the user selection?

Thanks!


Solution

  • It's like the following.

    @IBAction func popUpButtonUsed(_ sender: NSPopUpButton) {
        print(sender.indexOfSelectedItem)
    }