I have an outline view delegate and am overriding outlineView:dataCellForTableColumn:item: to make the cells in my outline view into buttons (see this question). Here is the code form my delegate:
- (NSCell *)outlineView:(NSOutlineView *)outlineView dataCellForTableColumn:(NSTableColumn *)tableColumn item:(id)item;
{
MyCell * myCell = [[MyCell alloc] init];
// return nil;
return myCell;
}
Doing this has a strange side effect. In my outline view's data source, the method outlineView:objectValueForTableColumn:byItem: always gets a null value for tableColumn.
The code is:
- (id)outlineView:(NSOutlineView *)outlineView objectValueForTableColumn:(NSTableColumn *)tableColumn byItem:(id)item
{
printf("tableColumn:%s\ttable identifier: %s\n", [[tableColumn className] cString], [[tableColumn identifier] cString]);
return [item valueForKey:[tableColumn identifier]];
}
And the output is:
tableColumn:(null) table identifier: (null)
What's strange is that this only happens when I implement the outlineView:dataCellForTableColumn:item: method. What am I missing here?
EDIT:
Modifying the delegate function like this seems to fix the problem:
- (NSCell *)outlineView:(NSOutlineView *)outlineView dataCellForTableColumn:(NSTableColumn *)tableColumn item:(id)item;
{
printf("delegate column identifier: %s\n", [[tableColumn identifier] cStringUsingEncoding:NSASCIIStringEncoding]);
if (tableColumn == nil)
{
return nil;
}
MyCell * aCustomCell = [[MyCell alloc] init];
return aCustomCell;
}
However, I don't really understand what's going on here. If anyone can explain, that would be helpful. Thanks!