Using NSOutlineView + NSTreeController + Core Data is resulting in odd outline view layout. As you can see in the images below, the outline view creates a space for the 'Child' when the 'Parent' is expanded but instead draws the 'Child' on top of the 'Parent'. I created a button that when pressed calls the [outlineVIew reloadData] method which causes the view to draw correctly.
Core Data model:
- parent
- children
- isLeaf
- name
My xib setup:
- NSOutlineView delegate is set to File's Owner
- NSTreeController is bound to my documents Core Data context
- NSTableColumn is bound to NSTreeController.arrangedObjects
- NSTextField is bound to NSTableCellView.objectValue.name
NSPersistentDocument Class:
- (void)windowControllerDidLoadNib:(NSWindowController *)aController
{
[super windowControllerDidLoadNib:aController];
Node *parent = [self createNodeOfTypeString:@"Node"];
Node *child = [self createNodeOfTypeString:@"Node"];
parent.name = @"Parent";
parent.isLeaf = NO;
[parent addChildrenObject:child];
child.name = @"Child";
child.isLeaf = YES;
[self.treeController addObject:parent];
}
- (id)outlineView:(NSOutlineView *)ov objectValueForTableColumn:(NSTableColumn *)tableColumn byItem:(id)item {
return [item representedObject];
}
- (NSView *)outlineView:(NSOutlineView *)ov viewForTableColumn:(NSTableColumn *)tableColumn item:(id)item {
if ([[item representedObject] isKindOfClass:[Node class]]) {
// Everything is setup in bindings
return [ov makeViewWithIdentifier:@"MainCell" owner:self];
}
return nil;
}
Results:
Outline View With Parent Collapsed
Outline View With Parent Expanded and Child Drawn Atop
Name
coming from in the screenshot? It doesn't appear in the model. – TechZen