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?
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With