View-based NSTableView equivalent of tableView:willDisplayCell:forTableColumn:row?

Viewed 9289

In the past, with a cell-based NSTableView, you could modify attributes of the cell in the tableView:willDisplayCell:forTableColumn:row method (for example, setting a custom NSAttributedString for one of the cells to display). Is there an equivalent method for view-based table view's?

Implementing tableView:willDisplayCell:forTableColumn:row doesn't get called in a view-based table view, so I'm not sure what to do.

I want to set a NSAttributedString using the setAttributedStringValue method of the default NSTextField instance that is included in a NSTableCellView instance created from within Xcode.

My efforts so far always get undone by the table view itself. Any ideas?

4 Answers

I used this to change the color of the text in viewForTableColumn. I am reading the tableCellView from Interface builder.

- (NSView *)tableView:(NSTableView *)tableView viewForTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row
{
    NSTableCellView *result = [tableView makeViewWithIdentifier:tableColumn.identifier owner:self];
    result.textField.textColor = [NSColor redColor];
    return result;
}

Since the textcolor actually changes for me, I believe you should be able to set other attributes there as well.

Related