Can not modify header cell of Table View

470 views Asked by At

My Cocoa app has a view-based table view.

The table displays a week of the calendar, where each column is a day from (say) Sunday to Saturday.

I would like to highlight the column that corresponds to "Today" in some way; ideally, give a colored background to the textfield, with rounded corners; something like this:

enter image description here

(this is trivial to achieve in iOS. On macOS, with cells etc. instead of views and layers, everything seems so much more complicated...)

However, I am not even able to change the header cell's text or background color. The code below (Swift 3) is executed, however all column headers is displayed with the default colors :

let columns = tableView.tableColumns

// (currentWeek is an array of NSDate)
for (index, day) in currentWeek.enumerated() {        

    let column = columns[sundayIndex + index]

    if Shared.calendar.isDateInToday(day) {
        // THESE TWO LINES ARE EXECUTED, BUT...

        column.headerCell.textColor = NSColor.red 
        // ...NO EFFECT

        column.headerCell.backgroundColor = NSColor.black 
        // ...NO EFFECT
    }

    // THIS WORKS FOR EVERY ROW:
    column.headerCell.stringValue = formatter.string(from: day)  
}
0

There are 0 answers