Note that there are some explanatory texts on larger screens.

plurals
  1. PONSOutlineView not updating
    text
    copied!<p>I'm trying to hook up a view-based NSOutlineView to my model using an NSTreeController and bindings.</p> <p>My model consists of a main Node class (and subclasses of it). Every node can have 0 or more children. I'm storing the children in a C array (of Node objects) for performance reasons. I defined the <code>childrenKeyPath</code>, <code>countKeyPath</code> and <code>leafKeyPath</code> properties of my NSTreeController and implemented them in my Node class:</p> <pre><code>- (NSArray *)childNodes { return [NSArray arrayWithObjects:children_ count:childCount_]; } - (BOOL)nodeIsLeaf { return childCount_ &lt; 1; } - (NSUInteger)childCount { return childCount_; } </code></pre> <p>When I add a new child, I call <code>[self willChangeValueForKey:@"childNodes"]</code> before and <code>[self didChangeValueForKey:@"childNodes"]</code> after inserting it into the C array.</p> <p>I set up the bindings as described in the documentation. (I bound the Content Object of the NSTreeController to my root Node. I bound the Content of the NSOutlineView to the NSTreeController's arrangedObjects. I also bound the NSTextField to the NSTableViewCell's objectValue.name property)</p> <p>The initial configuration (the root object and it's children) is loaded fine upon running the app. I can also add new children to the root object. </p> <p>However when I try to add a new child to any node (<em>except</em> the root) that has no children yet (no disclosure triangle) the NSOutlineView doesn't update (still no triangle). The new node is inserted into the model correctly and the will/didChangeValue messages are sent, but the NSTreeController doesn't bother examining the new children array. Logging the 3 keyPath functions above doesn't print anything in this case. </p> <p>If I close the parent and expand it again, then the nodes are reloaded, the disclosure triangle is shown and I can expand the node to see the new node I just added. Why doesn't the NSTreeController examine the changes, even though I sent the KVO messages when changing the children array? </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