Re: NSTreeController: how do I select a model object?
Re: NSTreeController: how do I select a model object?
- Subject: Re: NSTreeController: how do I select a model object?
- From: Michael Babin <email@hidden>
- Date: Mon, 14 Oct 2013 17:49:00 -0500
On Oct 14, 2013, at 4:18 PM, Jens Alfke <email@hidden> wrote:
> With an NSOutlineView driven by an NSTreeController, I’m having trouble figuring out how to programmatically select an item: given one of my model objects, how do I tell the controller or view to select it?
>
> NSTreeController has a .selectedObjects property, which is great for _getting_ the selection, but for some reason it’s a read-only property (unlike in NSArrayController), so I can’t use it to _set_ the selection.
>
> But if I go through the outline view, its ‘item’ objects are the NSTreeNodes managed by the controller, not my model objects, and I don’t see any clean way to map from a model object to its tree node. It seems like I’d have to write a recursive function to search the entire NSTreeNode hierarchy for one whose representedObject is my model object. Surely that can’t be the only way to do this?
I used the method described here on a project using NSTreeController and bindings to populate an outline view:
http://blog.wilshipley.com/2006/04/pimp-my-code-part-10-whining-about.html
I'm not aware of any changes to NSTreeController/bindings that would replace this approach, but I'm always ready to be pleasantly surprised. :-)
_______________________________________________
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