I have a View-based NSOutlineView bound to a NSTreeController. Everything seems to work correctly until I implement the outlineView:isGroupItem:
method in my delegate, then the group header suddenly stopped showing up. Like this
I confirmed that If I were to change the NSOutlineView to cell-based then the group item shows up properly. Similar behavior is also observed for NSTableView. Has anybody else encountered this problem?
Solved it!
Turned out I had to implement the following method in the NSOutlineView
delegate
- (NSView *)outlineView:(NSOutlineView *)outlineView
viewForTableColumn:(NSTableColumn *)tableColumn
item:(id)item {
if ([self outlineView:outlineView isGroupItem:item]) {
NSString *vId = [[[outlineView tableColumns] objectAtIndex:0] identifier];
return [outlineView makeViewWithIdentifier:vId owner:self];
}
return [outlineView makeViewWithIdentifier:[tableColumn identifier] owner:self];
}
Apparently, by default view based NSOutlineView generate view for each cell in the table by locating the view with the same identifier as the column. In the case of a group item / group row however, there is no tableColumm
associated with that row, therefore the view turns out to be nil and not show up.
Playing around with apple's TableViewPlayground sample project really helped! Highly recommended!
Addendum: In Interface Builder if you add Source List object instead of Outline View, it will add two prototype view rows for you.
Allowing you to design different looking header and data rows and referring to them in code by their identifier.
Header Cell: Data Cell:
You can of course also manually add as many prototype view rows as you like.
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