I want to use the rowViewForRow for checking what color the background must be.
I have a stuct array with multiple data and it is an ranking.
When there is an first place the background has to become blue.
When not the background has to be white.
But when i run rowViewForRow the row isn’t created and nil.
In debug mode i can see that every record in the stuct array is passed and looped.
I’ve also tried to use the tableview.makeView but with the same result.
There is an nil on the new row.
func tableView(_ tableView: NSTableView, rowViewForRow row: Int) -> NSTableRowView? {
if tableView == tableview {
guard let _row = tableView.rowView(atRow: row, makeIfNecessary: false) else {
print("Rij: \(row) tableview: \(tableView)")
return nil
}
if self.pouleStandenStruct[row].plaatsing == 1 {
_row.backgroundColor = .blue
return _row
} else {
_row.backgroundColor = .gray
return _row
}
}
return nil
}
The output in my debug window is:
Rij: 0 bij tableview: <NSTableView: 0x100655e80>
Rij: 1 bij tableview: <NSTableView: 0x100655e80>
Rij: 2 bij tableview: <NSTableView: 0x100655e80>
Rij: 3 bij tableview: <NSTableView: 0x100655e80>
Rij: 4 bij tableview: <NSTableView: 0x100655e80>
Rij: 5 bij tableview: <NSTableView: 0x100655e80>