Observation NSTreeController is associated with CoreData objects for insert / delete

I am creating my own custom custom tree. To do this, I would like to watch NSTreeController for updates to all relationships of its elements. The NSTreeController is bound to the context of the CD managed object. Each depth level has its own CD Entity with parent / child / isLeaf properties. I need to maintain the same hierarchy in the view (and the order of the children items). If something is inserted, I'll start watching the child property. And I need to know the index path for the newly inserted object.

I would like to know exactly what was inserted / deleted, so I can start watching its inserts / deletions for my children. As I understand it, the standard way to do this is to "change" NSDictionary inside observValue: forKey ..., but changes are NULL.

I know this is a long time, but is there some good solution for this? I've seen some examples "save arrays" and then when the model changes, you compare the differences. Its harder for a tree. It also destroys memory and processor cycles. I have one workaround that I am testing. It's just a job, so I won't describe it yet.

+2


source to share


1 answer


How about subclassing NSTreeController and implementing its insert / delete methods. Something like this, for example.



- (void)insertObject:(id)object atArrangedObjectIndexPath:(NSIndexPath *)indexPath {

      // ... code to update your object relationships .. 
      // ... Take care here if you update any variables in your model (eg a sortindex) that would trigger KVO in the NSTreeController.  In those case you need to make the updates without triggering KVO by using setPrimitiveValue:forKey or get an infinite loop

      [super insertObject:object atArrangedObjectIndexPath:indexPath];

}

      

+1


source







All Articles