Re: Issue with -[NSOutlineView autosaveExpandedItems]
Re: Issue with -[NSOutlineView autosaveExpandedItems]
- Subject: Re: Issue with -[NSOutlineView autosaveExpandedItems]
- From: Ken Thomases <email@hidden>
- Date: Thu, 10 Jul 2014 15:57:33 -0500
On Jul 10, 2014, at 3:20 PM, Bill Cheeseman <email@hidden> wrote:
> How can I make an outline view reinstate the expanded and collapsed state of its rows across application launches?
>
> Building in Xcode 5.1.1 under OS X 10.9.4 Mavericks, I select the outline view nib file's Autosave checkbox for Autosave Expanded Items, which is equivalent to calling -setAutosaveExpandedItems:YES.
>
> I also implement the outline view data source method -outlineView:persistentObjectForItem: by returning -[NSKeyedArchiver archivedDataWithRootObject:item] and the data source method -outlineView:itemForPersistentObject: by returning -[NSKeyedUnarchiver unarchiveObjectWithData:object]. Doing this is the only sense I can make of the very cryptic reference document instructions, and this solution is echoed in some of the mailing list discussions I found.
>
> It works, up to a point. When I launch the application, NSLog calls tell me that it does call -outlineView:itemForPersistentObject: at launch on the archived objects for every row that I left expanded when I previously quit. I see the correct archived data items in my user defaults preferences file, so I know the application properly called -outlineView:persistentObjectForItem: when I previously quit. The archived data items unarchive correctly to the outline view items that were left expanded when I previously quit.
>
> However, the indicated rows are not expanded at launch. Instead, all rows are collapsed at launch.
>
> Has anybody made this work? How?
Are the items that result from unarchiving the persistent object the same items as your data source returns via -outlineView:child:ofItem:? I believe they have to be the same by pointer identity, not just equal as by -isEqual:.
Rather than archiving the item itself, you should perhaps archive uniquely identifying attributes of the item so that you can find the corresponding item among the new model and return that.
Regards,
Ken
_______________________________________________
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:
This email sent to email@hidden