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

标签 macos cocoa nstableview nstablecellview

我有一个基于 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/

相关文章:

xcode - "AUv3FilterExtension macOS"的签名需要开发团队

macos - Dock 中的 OSX 应用程序快捷方式文件夹和安装后的图标更新

iphone - NSMutableString 和 nil 用于内存管理

objective-c - 如何根据 NSTextField 的大小来调整 NSTableCellView 的大小?

eclipse - 在 Mac OS X 上安装 BlackBerry Eclipse JDE 插件

swift - 如何从按钮触发绑定(bind)操作?

cocoa - 不 initWithWindowNibName 设置窗口字段

objective-c - 将 1.8 的 Gamma 应用于 NSImage

objective-c - 调用 makeViewWithIdentifier :owner: causes ARC to re-create ivar

cocoa - NSTableView 崩溃