当 table 为空时,如何确定 NSTableView 中给定列的 NSTableCellView?

How to determine NSTableCellView for a given column in NSTableView when the table is empty?

我有一个包含一列的基于视图的 NSTableView 实例。我需要在填充 table 之前确定该列的 NSTableCellView 实例。我需要视图来确定它的高度以及它用于它包含的文本字段的字体。

我试过了

func view(atColumn: Int, row: Int, makeIfNecessary: Bool) -> NSView?

但它崩溃了,因为空 table 不包含任何行。

我试过为单元格使用标识符并调用

func makeView(withIdentifier: NSUserInterfaceItemIdentifier, owner: Any?) -> NSView?

但是 table 在 xib 中提供标识符后不显示任何数据。我认为这可能与 table 绑定到数组控制器有关。

因为在 IB 中构建 table 时,在 NSTableColumns 中创建了 NSTableCellView 的实例,我本以为会有一种查询列的视图的方法,但它没有出现就这样吧。

任何指导将不胜感激。

来自makeView(withIdentifier:owner:)

Note that a cell view’s identifier must be the same as its table column’s identifier for bindings to work. If you’re using bindings, it’s recommended that you use the Automatic identifier setting in Interface Builder.

使用 makeView(withIdentifier:owner:) 中 table 列的标识符,或对 table 列和单元格视图使用相同的标识符。