How to highlight a row in an NSTableView

I have an NSTableView in my application. now they say 8 columns on 48 rows.

I have a function that runs a specific specific column to see that the value or value in each cell is greater than a specific value. If so, I would like the application to highlight the line.

I read some reading, and I'm still looking for function calls or a process that will allow me to extract cells / rows / or a rectangle and let me change the color.

What are the functions and steps in changing the color of cells?

+3
source share
5 answers
- [NSTableView selectRowIndexes:byExendingSelection:]

Source

+5
source

To change the cell color, you can try this method

-(void)tableView:(NSTableView *)tableView willDisplayCell:(id)cell forTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row
{
   [cell setDrawsBackground:YES];
  if(row==0)
       [cell setBackgroundColor:[NSColor color];
   else if(row==1||row==2)
        [cell setBackgroundColor:[NSColor color];
    else
        [cell setBackgroundColor:[NSColor color];
}

.

+3

tableView

tableView:dataCellForTableColumn:row:

. dataCell .

0

If you are extracting data as rows, you can use: -

NSAttributedString

to change the color of text and background.

0
source
-(void)tableView:(NSTableView *)tableView willDisplayCell:(id)cell forTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row

... gives you a pre-created cell (usually an NSTextFieldCell) that you can then colorize. No need to return it - Apple has already done this and is going to use it, just change the object as you like. It works great.

0
source

Source: https://habr.com/ru/post/1718479/


All Articles