I have a checkbox button in a table column (of course in a NSTableCellView).
@IBAction func check_click(_ sender: Any) {
// How do I know in which row this event occurred?
// Once I get the row index I get the associated data item so that I can update the checked state.
}
No tag is not readonly. You can set it programmatically.
To get the row:
In the IBAction:
@IBAction func check_click(_ sender: UIButton) {
// How do I know in which row this event occurred?
var row = -1
if let theCell = sender as? UITableViewCell { // You may have to loop the superviews ; see below
if let path = self.tableView.indexPath(for:theCell) { row = path.row }
}
if row < 0 { return }
// Once I get the row index I get the associated data item so that I can update the checked state.
// You have it now
}
To loop:
@IBAction func check_click(_ sender: UIButton) {
// How do I know in which row this event occurred?
var row = -1
var view = sender // UIButton
while (view != nil && !view!.isKind(of: UITableViewCell.self) ) {
view = view!.superview
}
if let theCell = view {
if let path = self.tableView.indexPath(for:theCell) { row = path.row }
}
if row < 0 { return }
// Once I get the row index I get the associated data item so that I can update the checked state.
// You have it now
}