I have constructed a window with a single view-based NSTableView, programmatically (code-only, without XIB) following this, which is backed by an Array in swift. I instead want to back it by an NSArrayController so had it simply by:
var controller = NSArrayController()
and modify its contents, when needed, using one of its proper methods:
controller.addObject(item)
controller.removeObjectAtArrangedObjectIndex(index)
controller.insertObject(item, atArrangedObjectIndex: atIndex)
and bound it with:
tableView.bind(NSContentBinding, toObject: controller, withKeyPath: "arrangedObjects", options: nil)
tableView.bind(NSSelectionIndexesBinding, toObject: controller, withKeyPath:"selectionIndexes", options: nil)
tableView.bind(NSSortDescriptorsBinding, toObject: controller, withKeyPath: "sortDescriptors", options: nil)
Cell views are created in the delegate with:
func tableView(tableView: NSTableView, viewForTableColumn tableColumn: NSTableColumn?, row: Int) -> NSView? {
// ... erased code for finding cellIdentifier and text..
view = tableView.makeViewWithIdentifier(cellIdentifier, owner: nil) as? PLTextCellView
if view == nil {
print("new view for text: "+text)
view = NSTextField()
view!.identifier = cellIdentifier
}
view!.stringValue = text
return view
}
Add/remove and number of items work ok but object id's are displayed, in the cells, between '<' and '>', instead of the values I assign as text. This was working fine before the NSArrayController. What do I need to do?
Notes:
This question gives an -incomplete- answer which give An instance of ...item... was deallocated while key value observers were still registered with it.
error.
I also did bind my table according to this answer which only states a necessity to bind the cells also, manually. I am asking how?