• 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: NSArrayController KVO question...
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSArrayController KVO question...


  • Subject: Re: NSArrayController KVO question...
  • From: Randy Widell <email@hidden>
  • Date: Thu, 22 Nov 2012 12:31:06 -0800

You presume correctly.  Your suggestion makes perfect sense.  I was just reading about key dependencies yesterday, but didn't put 2 and 2 together because I wasn't think about the way the table view was setup.

Thanks for the help!


On Nov 22, 2012, at 12:16 PM, email@hidden wrote:

> 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


_______________________________________________

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

References: 
 >NSArrayController KVO question... (From: Randy Widell <email@hidden>)
 >Re: NSArrayController KVO question... (From: "email@hidden" <email@hidden>)
 >Re: NSArrayController KVO question... (From: Randy Widell <email@hidden>)
 >Re: NSArrayController KVO question... (From: "email@hidden" <email@hidden>)
 >Re: NSArrayController KVO question... (From: Randy Widell <email@hidden>)
 >Re: NSArrayController KVO question... (From: "email@hidden" <email@hidden>)

  • Prev by Date: Re: NSArrayController KVO question...
  • Next by Date: Re: NSFileManager - Incompatible persistent store
  • Previous by thread: Re: NSArrayController KVO question...
  • Next by thread: Re: NSArrayController KVO question...
  • Index(es):
    • Date
    • Thread