Note that there are some explanatory texts on larger screens.

plurals
  1. POView Based NSOutlineView Drawing Child Views Atop Parent Views
    text
    copied!<p>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. </p> <p>Core Data model:</p> <ul> <li>parent</li> <li>children</li> <li>isLeaf</li> <li>name</li> </ul> <p>My xib setup:</p> <ul> <li>NSOutlineView delegate is set to File's Owner</li> <li>NSTreeController is bound to my documents Core Data context</li> <li>NSTableColumn is bound to NSTreeController.arrangedObjects</li> <li>NSTextField is bound to NSTableCellView.objectValue.name</li> </ul> <p>NSPersistentDocument Class:</p> <pre><code>- (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; } </code></pre> <p>Results:</p> <p>Outline View With Parent Collapsed</p> <p><img src="https://i.stack.imgur.com/bpExK.png" alt="Outline View With Parent Collapsed"></p> <p>Outline View With Parent Expanded and Child Drawn Atop</p> <p><img src="https://i.stack.imgur.com/JIIIL.png" alt="Outline View With Parent Expanded and Child Drawn Atop"></p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload