Coloring NSTableView text in a row

I have an NSTableView that displays an array of objects that I have. For each of these objects (lines), I would like to change the color of the displayed text depending on the results of the function that I run for each object;

So, for example, the entire object in the table that exists in another list (or some other requirement), I want to display them in green text, and objects that do not exist are displayed in red.

How should I do it?

+5
source share
1 answer

, NSTextFieldCell ( ), NSTableView.

-, NSTableView Builder, . , .

:

- (void)tableView:(NSTableView *)aTableView willDisplayCell:(id)aCell forTableColumn:(NSTableColumn *)aTableColumn row:(NSInteger)rowIndex {
    NSTextFieldCell *cell = aCell;
    if (...) {
        [cell setTextColor:[NSColor greenColor]];
    } else if (...) {
        [cell setTextColor:[NSColor redColor]];
    } else {
        [cell setTextColor:[NSColor blackColor]];
    }
}

, NSTableView , , .

NSTableViewDelegate.

+6

All Articles