I have a view-based NSTableView
and I'm trying to customize the appearance of certain rows.
I understand I need to implement the delegate method mentioned in the title; However I'm not sure about how to do it.
The documentation says:
You can use the delegate method tableView:rowViewForRow: to customize row views. You typically use Interface Builder to design and lay out NSTableRowView prototype rows within the table. As with prototype cells, prototype rows are retrieved programmatically at runtime. Implementation of NSTableRowView subclasses is entirely optional.
However, unlike cells, there is no NSTableRowView
class in interface builder, nor is it clear how to setup a "prototype" row view.
I am trying something like this (Swift 3):
func tableView(_ tableView: NSTableView, rowViewForRow row: Int) -> NSTableRowView?
{
if (row % 4) == 0 {
// ..................................................
// [ A ] SPECIAL ROW:
if let rowView = tableView.make(withIdentifier: "SpecialRow", owner: self) as? NSTableRowView {
rowView.backgroundColor = NSColor.gray()
return rowView
}
else {
return nil
}
// ^ Always returns nil (Because I don't know how
// to setup the prototype in Interface Builder)
}
else{
// ..................................................
// [ B ] NORMAL ROW (No customization needed)
return nil
}
}
I have similar code working for cells -i.e., -tableView:viewForTableColumn:row:
.