On Apr 11, 2008, at 12:10 AM, Quincey Morris wrote:
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.


I got it to work. What you say makes a lot of sense now, thanks very much for helping me understand what really was wrong with the code. Of course it solved the leaking problem and works really nicely. I'm new to the concept that a node (or any object) will change its class to something else once added to the KVO structure appropriately and "learns" new things as it's added. It's quite cool.

Thanks again!

Regards
Markus

PS: Question remains why Apple doesn't know how to really do this - it's the sample project I got this code from.
--
__________________________________________
Markus Spoettl

_______________________________________________

Cocoa-dev mailing list ([email protected])

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