I'm having a hard time with this. I am getting a very odd behavior when it comes to object persistence of a view based NSOutlineView. Currently I have an object that contains an array of object1 that contains an array of object2 that contains an array of object3, etc... Each each class (object) has an isEqual: method and an isEqualToObject: method. I have revised these over and over again, they work fine.
Now when I expand an item, it is saved to the defaults plist and I have checked it, the number of items saved is correct.
What happens though is that when I open my document again; sometimes all the rows are expanded exactly as I left them, sometimes none of the rows are expanded and sometimes NSOutlineView will expand some rows but not others.
To note I am not using NSTreeController. I am using NSOutlineView DataSource and Delegate. The following methods are implemented like this. Also the AutoSave name for the outline view is set.
- (id)outlineView:(NSOutlineView *)outlineView persistentObjectForItem:(id)item {
return [NSKeyedArchiver archivedDataWithRootObject:item];
}
- (id)outlineView:(NSOutlineView *)outlineView itemForPersistentObject:(id)object {
return [NSKeyedUnarchiver unarchiveObjectWithData:object];
}
Basically sometimes it works, sometimes it half works and sometimes not at all. It is very random.
The odd thing is that I've placed NSLog and each item is finding a match but... the outline view is not expanding it.
[item representedObject]
to get the underlying object aka as in your model. – VolkerawakeFromNib
of my document class[self.groupView setAutosaveExpandedItems:YES];
. I remember reading that you have to call it manually. I assume you also have set the autosave name? – Volker