I’m using a view-based table view and don’t want it to draw NSTextFields with white text color when it is selected.
I was not able to find a working solution. So any help is very appreciated.
Here is my problem:

I want the “Selection is white” text also be drawn in the default text color.
So far I figured out that
- Setting attributes in
tableView:viewForTableColumn:item:does not really help - Setting
NSTextFieldcolor to a custom color, which is something different than the control default color, will prevent from drawing in white but it still looses font style (bold, italic, etc). - Setting
NSTableView‘sselectionHighlightStyleattribute toNSTableViewSelectionHighlightStyleNonedoes the trick but it will not redrawNSTableRowView. Also the select style is not what I want. I want the first click to select the row and the second click to edit the text field. When you useNSTableViewSelectionHighlightStyleNoneyour first click starts editing the text field. - The text color does not change if the NSTextField is bordered. But I don’t want bordered text fields (As shown in the screenshot. The text fields are editable)
I couldn’t figure out ‘how’ the text field gets the white color. I have overridden setTextColor: and realized that it is never called when selection is changed. So I guess an NSAttributedString is built somewhere inside the NSTableView drawing/selecting routine.
Any help is very much appreciated.
I found the answer. I had to subclass
NSTableCellViewand overridesetBackgroundStyle:. That’s all!