I have a NSOutlineView that show the content controlled by a NSTreeController which I bind to an NSMutableArray (arrayOfFiles). The array contains NSTreeNode objects where the representedObject (Fileobject class) holds a number of ivars. I would like to edit and update the ivar named "direction" for specific objects. I manage to get my object of interest using a NSIndexPath which I have stored for each object.
[self.myOutlineViewController.myTreeController setSelectionIndexPath:myIndexPath];
Fileobject *myObject =[[[self.myOutlineViewController.myTreeController.arrangedObjects descendantNodeAtIndexPath:myIndexPath] representedObject] representedObject];
[myObject setDirection:0];
This works fine, but I run into problems when I want to update the object I just extracted at NSIndexPath. The following crashes:[self.myOutlineViewController.myTreeController removeObjectAtArrangedObjectIndexPath:myIndexPath]; with the error message
An uncaught exception was raised
2012-11-08 17:23:25.557 S3access[20379:12b03] *** -[NSKeyValueSlowMutableArray removeObjectsAtIndexes:]: value for key myArrayOfFiles of object 0x40012e460 is nil
I understand i am doing something wrong with Key-Value coding here but I am unable to see what it is. I have tried to seek solutions in all of the examples from Apple but I can only find examples that do not use NSTreeController and NSTreeNode. My thought was to 1) extract the object at indexpath 2) edit the extracted object 3) remove current object at indexpath 4) insert my new edited object into indexpath using command [self.myOutlineViewController.myTreeController insertObject:myNode atArrangedObjectIndexPath:myIndexPath];. I dont see how I can replace my object using Key-Value coding when I dont replace only an ivar but the whole object?
Any suggestions for what I am doing wrong and suggestions for how I may solve this is highly appreciated.
Cheers, and thanks! Trond