I have a simple view based NSTableView with one column which is populated with Core Data entities, and the row's view contains just a NSTextField. I need ONLY the first row to be non editable, and to be displayed in red. I tried to to this somewhere in applicationDidFinishLaunching :
NSView *myView = [myPlaylistsTableView viewAtColumn:0 row:0 makeIfNecessary:NO];
NSArray *mySubviews = [myView subviews];
NSTextField *myTextField = [mySubviews firstObject];
[myTextField setEditable:NO];
NSDictionary *myDictionary = [NSDictionary dictionaryWithObjectsAndKeys:[NSColor redColor],NSForegroundColorAttributeName, nil];
NSAttributedString *myRedAttributedString = [[NSAttributedString alloc] initWithString:@"All Songs" attributes:myDictionary];
[myTextField setAttributedStringValue:myRedAttributedString];
But as soon as a new element is added in the table, or a drag in performed, the first row gets editable again. I have tried to write a value transformer, binding the NSTextField editable binding to the array controller selectionIndex, and return NO if selectionIndex is 0, yes in all other cases. This does not work, with various configurations of the value binding's conditionally set editable checkbox. I guess also a subclass of NSTableView should do the trick but I am a bit lost on this side. Any help is as always greatly appreciated. Thanks.
As suggested by @Joshua Nozzi, I am implementing this delegate method for the table view :
-(NSView *)tableView:(NSTableView *)tableView viewForTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row
{
NSView *myView = [tableView makeViewWithIdentifier:[tableColumn identifier] owner:self];
if (tableView == myPlaylistsTableView)
{
if (row == 0)
{
NSArray *mySubviews = [myView subviews];
NSTextField *myTextField = [mySubviews firstObject];
[myTextField setEditable:NO];
NSDictionary *myDictionary = [NSDictionary dictionaryWithObjectsAndKeys:[NSColor redColor],NSForegroundColorAttributeName, nil];
NSAttributedString *myBoldAllSongsString = [[NSAttributedString alloc] initWithString:@"All Songs" attributes:myDictionary];
[myTextField setAttributedStringValue:myBoldAllSongsString];
}
}
return myView;
}
But I must be missing something because the method is called for the correct NSTableView and row = 0, code gets executed but I still don't have a red string and the textfield is editable.
Thanks again for any help.