0

I have an NSTableCellView in a view based NSTableView which displays attributed text. So some of the words displayed are f.e. red, some blue, some bold, some normal.

The cell has white background, but as soon as the user clicks on one of the cells, I'd like to display it with a different background color and therefore need to set all the text to white for that state.

What would be the most elegant solution to this problem?

I know that I can just set the text again as normal text and not attributed text on selection and as attributed text if not selected. But then with bold and normal font it would get a bit tricky.

Is there a more elegant solution to that problem?

Georg
  • 3,664
  • 3
  • 34
  • 75

1 Answers1

0

I am not familiar with NSTableViewDelegate but in UITableViewDelegate you have:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath

find an alternative to this in NSTableViewDelegate and create a cell from the indexPath:

UITableViewCell *cell = tableView cellForRowAtIndexPath:indexPath]; 

then just alter its background

cell.backgroundColor = [UIColor redColor];

Hope this helps!

Valentin
  • 3,272
  • 1
  • 14
  • 22
  • They work a bit differently. I mean I already have a solution in place where my cell remembers the original attributet string and alters the color. I was just wondering about the most elegant solution to this problem... – Georg Oct 26 '14 at 10:39
  • Oh, and I was asking about the text color with attributed strings that also have color in them... – Georg Oct 26 '14 at 10:40