单击 UI 对象会在其更改之前NSComboBox
错误地执行,而不是顾名思义之后执行。它与.comboBoxSelectionDidChange(...)
.stringValue
.comboBoxSelectionIsChanging
实际更改后如何comboBoxSelectionDidChange(...)
执行?NSComboBox.stringValue
class ViewController: NSViewController, NSComboBoxDelegate {
@IBOutlet weak var comboBox: NSComboBox!
override func viewDidLoad() {
super.viewDidLoad()
self.usernameComboBox.delegate = self
}
func comboBoxSelectionDidChange(notification: NSNotification) {
print(usernameComboBox.stringValue)
// PRE-selected .stringValue = "ITEM 1"
// POST-selected .stringValue = "ITEM 2"
// selecting either item prints PRE-selected
}
}