• 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: Fri, 23 Nov 2012 16:45:51 -0800

Well, I implemented your method and still had issues.  Turns out the value binding for the drop-down menu was a secondary issue.  After implementing your method, I could verify that changing the property did, in fact, trigger an update in the table.  However, the values never changed in UI.  The object sent to setObjectValue: in my cell still had the original values.

Turns out the value binding with the drop-down menu was resetting the property.

I added a read-only property to my model that just returns the property:

  @property (assign) BOOL archived;
  @property (readonly) BOOL isArchived;

  - (BOOL) isArchived
  {
    return archived;
  }

Then, I bound the drop-down menu's value property to isArchived instead of archived, unchecked "Raises for Not Applicable Keys", and voila.

Everything works like a charm.

All of that said, since this drop-down menu is an "action" menu, it may be better to use the title property of the menu to switch the title between "Archive" and "Unarchive" rather than display a check mark next to "Archive".

Anyway, thanks again for your 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: Getting mouse events in view placed in NSTableRowView
  • Next by Date: Re: Getting mouse events in view placed in NSTableRowView
  • Previous by thread: Re: NSArrayController KVO question...
  • Next by thread: NSFileManager - Incompatible persistent store
  • Index(es):
    • Date
    • Thread