我有一个基于 View 的 NSTableView 实例,其中包含一列。我需要在填充表之前确定该列的 NSTableCellView 实例。我需要 View 来确定其高度以及它包含的文本字段使用的字体。
我已经尝试过
func view(atColumn: Int, row: Int, makeIfNecessary: Bool) -> NSView?
但它崩溃了,因为空表不包含行。
我尝试使用单元格标识符并调用
func makeView(withIdentifier: NSUserInterfaceItemIdentifier,owner: Any?) -> NSView?
但在 xib 中提供标识符后,表不显示任何数据。我认为这可能与表绑定(bind)到数组 Controller 有关。
由于在 IB 中构建表时,会在 NSTableColumns 中创建 NSTableCellView 的实例,因此我本以为会有一种方法来查询列中的 View ,但事实似乎并非如此。
任何指导将不胜感激。
最佳答案
来自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:)
中使用表格列的标识符,或者对表格列和单元格 View 使用相同的标识符。
关于macos - 当表为空时,如何确定 NSTableView 中给定列的 NSTableCellView ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58368803/