Re: NSArrayController KVO question...
Re: NSArrayController KVO question...
- Subject: Re: NSArrayController KVO question...
- From: "email@hidden" <email@hidden>
- Date: Thu, 22 Nov 2012 20:16:26 +0000
On 22 Nov 2012, at 18:57, Randy Widell <email@hidden> wrote:
> Right, and in other places it works for me. For instance, I have a window with text fields bound to a model object through an object controller. Updating properties of the model updates the text fields.
>
> Reading your test below, one thing I was forgetting is that I am not binding a column in the table view to any specific property. I have one column bound to arrangedObjects and a custom cell that draws all the information (think Apple Mail with the subject line and then a snippet below).
I do much the same in an outline control and everything updates via bindings fine.
The multi property cell output can be seen here.
http://www.mugginsoft.com/kosmictask/help/using#task-view-mode
> So, I guess it does make sense that the table view does not update. Perhaps reloadData after I change the item.
It makes sense.
I presume you update your custom cell via NSCell -setObjectValue and draw according to the object properties pass in as the argument.
This is fine for when the table is first drawn but there is no way for the array controller to learn when the model has been updated.
You are bound to the model, not a model property. This makes sense as the cell state depends on more than one model property .
You need a way of letting the bindings machinery that the model has been updated.
What I do is in my model object is to define a bindingObject property that returns self:
- (id)bindingObject
{
return self.
}
I then bind a NSTableView column to arrayController.arrangedObjects.bindingObject.
Now, in the model, you just set up a dependency between your bindingObject path and the paths that the custom cell is sensitive to (the affectingKeys in the sample below).
+ (NSSet *)keyPathsForValuesAffectingValueForKey:(NSString *)key
{
NSSet *keyPaths = [super keyPathsForValuesAffectingValueForKey:key];
if ([key isEqualToString:@"bindingObject"])
{
NSSet *affectingKeys = [NSSet setWithObjects:@"name", @"image", @"count", @"hasCount", @"countColor", @"statusImage", @"updating", @"updatingImageIndex", nil];
keyPaths = [keyPaths setByAddingObjectsFromSet:affectingKeys];
}
return keyPaths;
}
Thus, when, in the example above, I change say the count model property -didChangeValueForKey:@"bindingObject" is sent and the cell is redrawn using the new model properties.
HTH
Regards
Jonathan Mitchell
Mugginsoft LLP
_______________________________________________
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