开发者

View Based NSOutlineView Drawing Child Views Atop Parent Views

开发者 https://www.devze.com 2023-03-26 13:46 出处:网络
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\' i

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

View Based NSOutlineView Drawing Child Views Atop Parent Views

Outline View With Parent Expanded and Child Drawn Atop

View Based NSOutlineView Drawing Child Views Atop Parent Views


That's not a Core Data related problem. It's something in NSTreeController. Even if the data model returns the wrong values, they shouldn't be drawn over each other like that.

The tree controller is improperly bound somewhere. It should only have a single top node displaying "Parent". Instead, it has a second top node displaying "Name".

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号