Environment: View-based NSTableView WITHOUT Bindings.
Problem: Mapping column's checkbox action to its datasource.
Without using IB bindings, how do I associate any particular NSButton/Checkbox action with its respective NSTableView row?
I want to be able to update the checkbox's respective data array with its state.
That is, mapping an array of structs or closures with their 1:1 table entries. Hence, clicking on a 'select'/row updates its respective boolean flag with the data source array.
The following code snippet shows how I populate the UI:
typealias GeoTuple = (geoDesc:String,geoSelected:Int)
var geoList = [GeoTuple]()
func tableView(tableView: NSTableView, viewForTableColumn tableColumn: NSTableColumn?, row: Int) -> NSView? {
var cellView:NSTableCellView?
let cellID = tableColumn?.identifier
guard nil != cellID else {
cellView = NSTableCellView()
return cellView
}
cellView = (tableView.makeViewWithIdentifier(cellID!, owner: self) as? NSTableCellView)
guard nil != cellView else {
print("{ODYInitializePricingProductViewController} *** NO CELL VIEW GENERATED *** \n Check cell identifiers.")
return nil
}
let currentTableColumn = ODYInitPricingTableColumnIdentifier(rawValue:cellView!.identifier!)
switch currentTableColumn! {
...
case .geoSelectFlag:
if row < geoList.count {
if let selectButton = cellView?.viewWithTag(1) as? NSButton {
selectButton.integerValue = geoList[row].geoSelected
}
}
...
return cellView
}
Question: How do I trap for a specific NSButton-Check toggle event, and associate/map this event to its respective data source: geoList?
Aucun commentaire:
Enregistrer un commentaire