title: NSTableView (view based) with custom text colors and correct editing text color
body: <p>Changing the text color in a view based NSTableView can be accomplished by using a custom table cell view and implement <code>setBackgroundStyle</code>:</p>
  
  <pre><code>- (void)setBackgroundStyle: (NSBackgroundStyle)backgroundStyle {
    [super setBackgroundStyle: backgroundStyle];
  
    UICoverageElement *element = self.objectValue;
  
    if (backgroundStyle == NSBackgroundStyleEmphasized) {
      self.textField.textColor = NSColor.highlightColor;
    } else {
      if ([element.value isEqualToString: @"&lt;no name&gt;"]) {
        self.textField.textColor = NSColor.tertiaryLabelColor;
      } else if ([element.value hasPrefix: @"UI"]) {
        self.textField.textColor = typeColor;
      } else if ([element.value hasPrefix: @"["] || [element.value hasPrefix: @"{"]) {
        self.textField.textColor = objectColor;
      } else {
        self.textField.textColor = NSColor.textColor;
      }
    }
  }
  </code></pre>
  
  <p>This works nice and well:</p>
  
  <p><a href="https://i.stack.imgur.com/XLkP0.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/XLkP0.png" alt="enter image description here"></a></p>
  
  <p>but causes trouble when editing a cell. In this case the field editor obviously takes the current manually set text color (which is white for a selected row) and shows that in a field editor with white background:</p>
  
  <p><a href="https://i.stack.imgur.com/Lndak.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Lndak.png" alt="enter image description here"></a></p>
  
  <p>Now the question is: how can I set the correct text color when a cell view is being edited?</p>
  
  <p><code>setBackgroundStyle</code> is not called when editing starts, which makes it impossible to fix that problem in this function. I tried various methods that indicate start of the editing process, but none is called (but <strong>are</strong> called for standalone text fields). When I do not set the highlightColor then the editor color is correct but the highlight color of a selected row is wrong then.</p>