简体   繁体   中英

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

I have an instance of a view-based NSTableView containing one column. I need to determine the instance of NSTableCellView for that column prior to the table being populated. I need the view to determine its height and the font it uses for the text field it contains.

I have tried

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

but it crashes because the empty table contains no rows.

I have tried using an identifier for the cell and called

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

but the table displays no data after providing the identifier in the xib. I think that this may have something to do with the table being bound to an array controller.

Since, when constructing the table in IB, one creates instances of NSTableCellView in the NSTableColumns, I would have thought there would be a means of querying the column for the views, but it doesn't appear to be so.

Any guidance would be greatly appreciated.

From 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.

Use the identifier of the table column in makeView(withIdentifier:owner:) or use the same identifier for the table column and the cell view.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM