Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 470
willbur1984 Avatar asked Jul 26 '11 21:07

willbur1984


2 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.

like image 184
cellcortex Avatar answered Sep 30 '22 14:09

cellcortex


Apparently, NSTableViewDelegate has a few new methods:

- (NSView *)tableView:(NSTableView *)tableView viewForTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row
- (NSTableRowView *)tableView:(NSTableView *)tableView rowViewForRow:(NSInteger)row

I assume that for a view-based NSTableView, both of these will be called. I guess you need the first one of those.

like image 31
Rudy Velthuis Avatar answered Sep 30 '22 14:09

Rudy Velthuis