Using Swift, I have an NSTableView with four columns. Two of the columns have cells that I want the user to be able to edit.
In my Storyboard I have set the NSTextFieldCells to be
Behaviour: Editable Action: Sent on End Editing
I have created an @IBAction function to receive the action from the NSTextFieldCell but it never fires.
Everything about the NSTableView appears to work as expected – it displays the values that it should, however when I edit the editable cells the action never fires (and the cell values do not change, of course.)
What am I overlooking?
Thanks
I'm using a cell based NSTableView.
You should better read this old article:
Programmatically Editing Data in an NSCell-Based Table
Seems you need to implement tableView(_:setObjectValue:for:row:)
in your NSTableViewDataSource
:
func tableView(_ tableView: NSTableView, setObjectValue object: Any?, for tableColumn: NSTableColumn?, row: Int) {
guard let stringValue = object as? String else {
return
}
//Check `tableColumn` in a real implementation...
print("cell was edited")
print(stringValue)
infoForTableView[row] = stringValue
}
Generally, NSCell-based table view is sort of an older part of NSTableView, it is simpler in many simple cases, but less customizable.