I'm trying to diplay list of static cell views in a NSTableView.
What I've done:
Note
)idNode
Note
) as I can't delete itTable view content mode — View Based.
Here's my code:
extension SidebarController: NSTableViewDataSource {
func numberOfRows(in tableView: NSTableView) -> Int {
return 1;
}
func tableView(_ tableView: NSTableView, objectValueFor tableColumn: NSTableColumn?, row: Int) -> Any? {
let cellIdentifier = NSUserInterfaceItemIdentifier(rawValue: "idNote")
guard let cellView = tableView.makeView(withIdentifier: cellIdentifier, owner: self) as? NSTableCellView else {
NSLog("Cant create cell view for row \(row)!")
return nil
}
cellView.textField!.stringValue = "Hello, world!"
return cellView
}
}
tableView
is:
cellView
is returned (at least it seems so)But I'm getting:
What I'm doing wrong?
FYI, if I delete identifier for NSTableCellView, I'm just getting Table Cell View placeholder.
The problem was I was using wrong overloaded function. The proper was:
func tableView(_ tableView: NSTableView, viewFor tableColumn: NSTableColumn?, row: Int) -> NSView? {
let cellIdentifier = NSUserInterfaceItemIdentifier(rawValue: "Note")
guard let cellView = tableView.makeView(withIdentifier: cellIdentifier, owner: self) as? NSTableCellView else {
NSLog("Cant create cell view for row \(row)!")
return nil
}
cellView.textField!.stringValue = "Hello, world!"
return cellView
}
So, note the difference:
_ tableView: NSTableView, viewFor tableColumn
The reason Xcode didn't allow me to use it — there was no NSTableViewDelegate
in extension definition.
This function confirms to NSTableViewDelegate. Only NSTableViewDataSource declaration is insufficient.
So, to catch up: