Question

I have NSTableView in my application. right now say is 8 columns by 48 rows.

I have a function that runs a specific a specific column to see wether or not the value in each cell is greater than a certain value. If it is I would like the application to highlight the row.

I did some reading and I am still looking for the functions calls or a process that will let me extract the cells/rows/or rect and let me change the color.

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

Was it helpful?

Solution

- [NSTableView selectRowIndexes:byExendingSelection:]

Source

OTHER TIPS

To change the color of the cell 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];
}

this will make your row with different color.

Set a tableView delegate and implement the

– tableView:dataCellForTableColumn:row:

method. Then write a custom dataCell class to do the custom drawing.

If you extract the data as strings, you can use :-

NSAttributedString

to change the colour of both text and background.

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

...gives you the pre-made cell (usually a NSTextFieldCell) which you can then color. Don't need to return it - Apple has already made it and is about to use it, just modify the object as you see fit. Works great.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top