I've got a CoreData object graph with an outline view showing
instances of an NSManagedObject subclass called "Group".
The Group class has the standard to-one relation 'parent' and to-
many 'children'.
The outline view is working perfectly.
I've set autosaveExpandedItems to YES and when I expand or unexpand
(contract?) a group my outline view's data source gets sent the
persistentObjectForItem message.
Collapse is the word used in the docs.
I can see in the prefs plist for my app that the expanded Group
itmes are being saved, and when my application launches, the outline
view's data source object gets sent the itemForPersistentObject
message.
Below is what I'm doing for each of these messages:
The persistentObjectForItem method successfully archives and returns
the 'uid' property for the item's represented object - this is a
unique identifier for each of my Groups.
The itemForPersistentObject successfully reconstitutes the archived
uid and correctly finds the Group with the unique 'uid' property and
returns it.
Expanded items in the outline view are not being restored however.
Is itemForPersistentObject expecting me to return something else?
My guess would be that it was expecting an instance of NSTreeNode,
since this is what I first got as 'item' in persistentObjectForItem.
Sadly though, I can't see a way to get an NSTreeNode from an object.
I have [item representedObject] for archival, but not [object
representingItem], if you see what I mean.
Obviously I've tried returning an the 'item' archived but it doesn't
respond to archiving.
Neither (obviously) does my NSManagedObject subclass... should I
implement archiving in my subclass to get this to work?
Does anyone have any clue they can distribute my way? (citation: http://www.bofhcam.org/co-larters/distributing-clue/index.html)
I've seen lots in the usual places (lists.apple.com,
cocoabuilder.com et al) about this but no actual solutions shout out
at me. Perhaps I'm not looking hard enough. (most likely).
Many TIA
Ian
I have this working in my app and I'm doing almost exactly the same
thing. I'm also using the UID as the persistent object so you don't
have to return an archived version of your whole model object or the
tree node.
I would check two things:
1. Are you setting the autosaveName to the outline view?
2. Maybe the outline view is trying to restore the expanded state
before your tree controller has content? You said
itemForPersistentObject returns the correct Group, but this actually
happened to me before, so just making sure :)
Beyond those two, if you still can't figure out why it's not working,
saving and restoring expanded state of an outline view is a trivial
task. I use the following bit of code in an NSOutlineView subclass to
do just that:
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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/email@hidden
This email sent to email@hidden