• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: NSTreeController: how do I select a model object?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSTreeController: how do I select a model object?


  • Subject: Re: NSTreeController: how do I select a model object?
  • From: Charles Srstka <email@hidden>
  • Date: Tue, 15 Oct 2013 02:53:46 -0500

On Oct 14, 2013, at 8:32 PM, Jens Alfke <email@hidden> wrote:

> On Oct 14, 2013, at 3:49 PM, Michael Babin <email@hidden> wrote:
>
>> 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. :-)
>
> Well, the big change is that what Wil in 2006 called the "strange little shadow objects that point to your REAL objects when you put real objects into an NSTreeController” are now public API, as NSTreeNode instances. This makes it feasible to navigate the controller’s tree without having to do a lot of NSIndexPath gunk the way his code does.
>
> These days, to get the index paths of model objects you “simply” have to recurse down the NSTreeNode hierarchy, which is still a mess but probably a lot more efficient than Wil’s 2006 code. So I guess it’s time for me to write that code...

I've found that it's far more efficient to recurse *up* the NSTreeNode hierarchy — e.g. start with the object you're looking for, then look at its parent, then its grandparent, etc. until you end up at the root. This way you only have to iterate through the objects that make up your object's family tree, instead of having to search the whole hierarchy the way Shipley's code does (causing all sorts of unnecessary nodes to be lazily created in the process). Of course, your objects have to have a reference back to their parents for this to work.

Charles

_______________________________________________

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


  • Follow-Ups:
    • Re: NSTreeController: how do I select a model object?
      • From: Jens Alfke <email@hidden>
References: 
 >NSTreeController: how do I select a model object? (From: Jens Alfke <email@hidden>)
 >Re: NSTreeController: how do I select a model object? (From: Michael Babin <email@hidden>)
 >Re: NSTreeController: how do I select a model object? (From: Jens Alfke <email@hidden>)

  • Prev by Date: Re: This document’s file has been changed by another application since you opened or saved it.
  • Next by Date: How test whether Mac app is running in Xcode?
  • Previous by thread: Re: NSTreeController: how do I select a model object?
  • Next by thread: Re: NSTreeController: how do I select a model object?
  • Index(es):
    • Date
    • Thread