On Jun 18, 2010, at 5:53 PM, Tony Romano wrote:

> Scenario:  Adding a new node to a NSOutlineView backed by a NSTreeController.
> 
> 1. Create a new internal object add add it to the data store(file system).  
> This will be my representedObject in the treecontroller
> 2. Compute the path and call insertObject:atArrangedObjectIndexPath:
> 
> the treecontroller does 2 things during the call to insertObject:
> 
> 1. It calls my getter, children, and asks me for all the children under the 
> parent node I have added the new node to.  I give it the list INCLUDING the 
> newly created node since it is now in the store.
> 2. Then it calls the setter, setChildren,  and gives me the newChildren list. 
>  Which now has an additional copy of the new node, one from the getter call 
> and one from the insertAt call. I know this for a fact because I purposely 
> added some data to the newly created node for the insert to distinguish them.
> 
> From the UI, the outlineview is correct, but my internal child list has the 
> extra node.  It's not displayed because the treecontroller optimizes when to 
> ask me for a childlist.  I have a work around which I don't like to basically 
> lock out the getter method and just return the current child list(i.e the 
> previous child list which doesn't have the new node added from the file 
> system).  Anyone experience this before and have a recommendation?

I will qualify this by saying that I don't have much direct experience with 
using NSTreeController.

In this case, it appears that the problem is that you are effectively adding 
the new object twice. Your step 1 adds it directly to your model. If this was 
done in a KVO compliant way, then the NSTreeController should take note of the 
change and update the NSOutlineView for you (making step 2 unnecessary). 
Alternatively, you could add the new object to your model through the 
NSTreeController (your step 2) and omit step 1.

_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to