0

基于单元格的 NSTableView 有一个从 NSTextFieldCell 派生的Name列,其中除了文本之外,它还绘制了一个自定义的饼进度指示器(在同一个单元格中,而不是在单独的列中)。NameCell

当下载一个大文件时,它会模仿 Finder 的名称列中的那个。

我已将列的值绑定到 filesAC数组控制器以显示文本字段,

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

但是如何将 的 绑定pieProgressNameCellprogress数组中的File对象)?

4

2 回答 2

0

我认为您需要将列绑定到数组控制器中的对象,而不是fileName属性。即"arrangedObjects"用作关键路径,而不是"arrangedObjects.fileName".

然后,您的自定义单元格类将覆盖objectValue. 它将fileName新对象的属性传递给超类,但也将对象保留为自己的值。您还必须覆盖 getter 才能返回该对象。

当您需要进度指示器的值时,您将查阅progress当前值对象的属性。

综上所述,使用基于视图的表格视图。:)

于 2020-05-17T04:01:34.697 回答
0

基于单元格的解决方案将意味着dataCell(forRow:)从 NSTableColumn 重写,以便返回自定义子类单元格NameCell并根据行设置绑定NameCell.progress。但dataCell(forRow:)已弃用。

基于视图的解决方案是在 FilesTable 类中:

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)
 ...
 }
于 2020-05-16T21:06:07.463 回答