0
votes

A cell-based NSTableView has Name column with a NameCell derived from NSTextFieldCell in which, besides the text it draws a custom pie progress indicator (in the very same cell, not in a separate column).

It mimics the one in Finder's Name column, when a big file is downloaded.

I've bound the column's value to the filesAC array controller in order to show the text field,

 columnName.bind(.value, to: filesAC as Any, withKeyPath: "arrangedObjects.fileName", options: nil)

But how to bind the pieProgress of the NameCell to the progress (of the File object in the array) ?

2
Why do you use a pattern (cell-based) which is outdated for almost 10 years?vadian
I made already a working view-based version but... Potentially over 1M rows. Outdated, not deprecated.WorkingClassHero
See NSTableView.h "Note: cell-based NSTableViews are deprecated in Mac OS 10.10. Prefer the view-based interface.". Is the user going to read 1M rows? Is the cell editable?Willeke
Cell-based table API is deprecated except tableView(_ : dataCellFor: row: ) and tableView(_ : willDisplayCell: for: row: ). I think it means that cell-based tables are not entirely deprecated but only the usage of custom subclasses of NSCell is. In other words, one can safely use cell-based table only with "standard" cells.WorkingClassHero

2 Answers

0
votes

I think you would need to bind the column to the objects in the array controller, not the fileName property. That is, use "arrangedObjects" as the key path, not "arrangedObjects.fileName".

Then, your custom cell class will override the setter for objectValue. It would pass the fileName property of the new object on to the superclass but would also retain the object as its own value. You would have to override the getter, too, to return that object.

When you need the value for the progress indicator, you would consult the progress property of the current value object.

All of that said, use a view-based table view. :)

0
votes

A cell-based solution would imply overriding dataCell(forRow:) from NSTableColumn in order to return the custom subclassed cell NameCell and set the binding for the NameCell.progress, as per row. But dataCell(forRow:) is deprecated.

A view-based solution is, inside FilesTable class:

self.bind(.content, to: filesAC as Any, withKeyPath: "arrangedObjects", options: nil)
...
func tableView(_ tableView: NSTableView, viewFor tableColumn: NSTableColumn?, row: Int) -> NSView? {
 ...
  cell = NameCellView(frame:frame)
  cell.bind(NSBindingName(rawValue: #keyPath(NameCellView.progress)), to: cell, withKeyPath: "objectValue.progress", options: nil)
 ...
 }