Re: Model changes behind NSTreeController's back
Re: Model changes behind NSTreeController's back
- Subject: Re: Model changes behind NSTreeController's back
- From: Mark Alldritt <email@hidden>
- Date: Thu, 15 Feb 2007 17:54:57 -0800
- Thread-topic: Model changes behind NSTreeController's back
Hi,
>> My custom view posts KVO notifications when it changes the model, but
>> NSTreeController is failing to notice and as a result, the
>> NSOutlineView
>> falls out of sync.
>>
> Why is the view posting KVO noticiations?
>
> <http://developer.apple.com/documentation/Cocoa/Conceptual/CocoaBindings/Conce
> pts/HowDoBindingsWork.html
>>
I misspoke. My view is updating the model through setters on the model
objects which in turn post the KVO notifications. My view is also observing
the model objects in order to update its own representation of the model as
and when needed.
In my current instance of this problem, when I insert or remove objects in
my child array, NSTreeController updates the NSOutlineView correctly, but
movement within the child array is missed. In a nutshell, this is what I'm
doing in my view class:
...
// This code fails...NSOutlineView does *not* update
NSMutableArray* children = [NSMutableArray
arrayWithArray:[observedObject children]];
id child = [[[children objectAtIndex:x] retain] autorelease];
[children removeChildAtIndex:x];
[children insertObject:child atIndex:y];
[observedObject setChildren:children];
...
// This code works... NSOutlineView does update
NSMutableArray* children = [NSMutableArray
arrayWithArray:[observedObject children]];
id child = [[[MyChildClass alloc] init] autorelease];
[children insertObject:child atIndex:y];
[observedObject setChildren:children];
...
// And this code works too
NSMutableArray* children = [NSMutableArray
arrayWithArray:[observedObject children]];
[children removeChildAtIndex:x];
[observedObject setChildren:children];
...
And setChildren looks like this:
- (void) setChildren:(NSArray*) newState
{
if (newState != mChildren)
{
[mChildren release];
mChildren = [children retain];
}
}
Cheers
-Mark
------------------------------------------------------------------------
Mark Alldritt Late Night Software Ltd.
Phone: 250-380-1725 Script Debugger 4.0 - AppleScript IDE
WEB: http://www.latenightsw.com/ FaceSpan 4.3 - AppleScript RAD
Affrus 1.0 - Perl Debugging
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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