• 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: Question about NSTreeController/NSOutlineView instance cleanup
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Question about NSTreeController/NSOutlineView instance cleanup


  • Subject: Re: Question about NSTreeController/NSOutlineView instance cleanup
  • From: Quincey Morris <email@hidden>
  • Date: Fri, 11 Apr 2008 00:10:59 -0700


On Apr 10, 2008, at 23:01, Markus Spoettl wrote:

Yes that must be it. I'm not sure how I manage to do that, though. Basically what I do is this:

NSIndexPath *location = [NSIndexPath indexPathWithIndex: [treeContent count]];

 TreeNode *rootnode = [[TreeNode alloc] init];
 ... set treenode properties ...

[treeController insertObject:rootnode atArrangedObjectIndexPath:location];

 ... do something that involves rootnode like adding sub-nodes ...

 [rootnode release]

The treeController will retain rootnode at the time insertObject is called and also adds rootnode to treeContent. Again, at least that's what I thought. There is no other place in the code that deals with or releases/retains TreeNode objects.

Well, without knowing the details of what you're doing, it's impossible to be certain, but this code certainly looks *very* wrong. For one thing, 'insertObject' is (according to the documentation) for controller subclasses to use to customize their own behavior, not for other things to use to insert objects. Normally, you don't want to mess with trying to change arrangedObjects directly.


For another thing, assuming you're approaching this using MVC design principles, this code gets things exactly backwards -- when setting up your data model, you don't make changes to the controller and expect them to be reflected in the model -- you make changes in the model and let them be reflected (via the controller) in the view.

Again assuming there's nothing very strange intended here, all you need to do is update treeContent in a KVO-compliant way, which (in the case of arrays) is:

[[myDocument mutableArrayValueForKey:@"treeContent"] addObject:rootnode];

(or some variant such as insertObject...) and the tree controller will see the change and update the user interface.

There are also other ways to change treeController in a KVO-compliant way, but mutableArrayValueForKey seems the most direct in this case.

P.S. Your retain/release stuff is fine as is.


_______________________________________________

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: Question about NSTreeController/NSOutlineView instance cleanup
      • From: mmalc crawford <email@hidden>
    • Re: Question about NSTreeController/NSOutlineView instance cleanup
      • From: Markus Spoettl <email@hidden>
    • Re: Question about NSTreeController/NSOutlineView instance cleanup
      • From: Markus Spoettl <email@hidden>
References: 
 >Question about NSTreeController/NSOutlineView instance cleanup (From: Markus Spoettl <email@hidden>)
 >Re: Question about NSTreeController/NSOutlineView instance cleanup (From: Markus Spoettl <email@hidden>)
 >Re: Question about NSTreeController/NSOutlineView instance cleanup (From: Quincey Morris <email@hidden>)
 >Re: Question about NSTreeController/NSOutlineView instance cleanup (From: Markus Spoettl <email@hidden>)
 >Re: Question about NSTreeController/NSOutlineView instance cleanup (From: Quincey Morris <email@hidden>)
 >Re: Question about NSTreeController/NSOutlineView instance cleanup (From: Markus Spoettl <email@hidden>)

  • Prev by Date: Core Data, Threads and Document based app
  • Next by Date: NSTableView - hiding columns
  • Previous by thread: Re: Question about NSTreeController/NSOutlineView instance cleanup
  • Next by thread: Re: Question about NSTreeController/NSOutlineView instance cleanup
  • Index(es):
    • Date
    • Thread