2

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
    }
}
4

2 に答える 2

1

より短い方法は次のとおりです。

     func comboBoxSelectionDidChange(notification: NSNotification) {

    guard let stringValue = usernameComboBox.objectValueOfSelectedItem as? String else { return }
    print(stringValue)
}
于 2016-07-14T14:30:37.010 に答える