swift - 选择后的osx NSPopUpButton通知

标签 swift macos notifications nspopupbutton

我需要知道用户从 NSPopUpButton 更改项目后的用户选择。

为什么 NSPopUpButton 控件会在用户操作之前发出通知。

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

实现 NSPopUpButton 通知效果很好:

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

但是我怎样才能在用户选择后触发一个 Action /方法呢?

谢谢!

最佳答案

就像下面这样

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

关于swift - 选择后的osx NSPopUpButton通知,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42462213/

相关文章:

ios - 提取出子字符串但出现编译器错误

ios - 在 UI TableView 中滚动时文本重叠?

C++ 在 Windows 上编译但在 OS X GCC 下出错

ios - 如何防止用户不删除 UITextField 中的特定字符?

windows - 如何为我的应用程序设置 Windows 10 通知首选项

objective-c - 当 View Controller 即将在 iOS4 中弹出时得到通知

ios - Swift UITableView 不显示内容

iOS 加载自定义注解

objective-c - 检测其他进程正在使用的文件

macos - NSImage TIFFRepresentation 未随 ARC 一起发布