On 1 Jul 2008, at 17:19, Ron Lue-Sang wrote:


On Jul 1, 2008, at 12:05 AM, Andy Kim wrote:

Thanks - I've seen solutions like this before, I just wanted to get it working the regular way!

I totally understand the sentiment.

Is itemForPersistentObject expecting an NSTreeNode? You say you have it working in a similar way - what does your itemForPersistentObject method return?

Many thanks
Ian

Here's what I do:

- (id)outlineView:(NSOutlineView *)ov itemForPersistentObject: (id)object
{
return [[gAppDelegate library] groupWithUID:object]; // This fetches the group from the managed object context
}

- (id)outlineView:(NSOutlineView *)ov persistentObjectForItem: (id)item
{
        return [item uid];
}

According to the docs I'm supposed to archive the persistent object before returning it, but in my case, it doesn't matter because it's just a string and it all goes into a plist anyway. I have tried it both ways after seeing your implementation though, and there are indeed no differences.

I see why you're thinking that you need to return a NSTreeNode though. I don't need to do that because I don't use a NSTreeController and instead implement the data source protocol in my custom controller. So for me the item is the model object itself.

In your case, I'm fairly positive that you do need to return the NSTreeNode object. Instead of fetching the model object, walk the controller's content tree looking for the right representedObject with the UID.

- Andy Kim


Andy, you're right.
Ian's code needs to return an NSTreeNode. Please file a bug that this is too hard.


I played around some more with this and came to the conclusion that it's impossible to implement auto saving of expanded items using itemForPersistentObject and persistentObjectForItem NSOutlineView delegate methods, when the outlineview has an NSTreeController as it's datasource.

The reason I think this, is that the outlineview is populated with instances of NSTreeNode. At application launch, persistentObjectForItem is called before the tree has been populated. I think what goes on behind the scenes, is that a record of which nodes are expanded and which are collapsed is saved in the app defaults, persistentObjectForItem is called to get the object in question and next time the outlineview 'sees' that object from it's datasource it knows whether to expand that node or not.

The trouble is, the outlineview will never 'see' *anything* you return in persistentObjectForItem since all it will ever see are NSTreeNode instances none of which exist yet.

Hope that makes sense! AFAIK, it's not just hard, but un-doable!

Thanks everyone for your help - I've gone over to the regular datasource way of doing things and everything's swell.

Cheers
Ian

_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]

Reply via email to