Re: Trying To Understand Bindings
Re: Trying To Understand Bindings
- Subject: Re: Trying To Understand Bindings
- From: Ashley Clark <email@hidden>
- Date: Sat, 13 Dec 2008 01:59:21 -0600
On Dec 13, 2008, at 12:19 AM, Bridger Maxwell wrote:
Just when I thought I had bindings down....
I have a custom view subclass (sineWaveView) that the user interacts
with to change a property (connectedContact). I would like to bind
this to a value (selectedShortRangeContact) in a dictionary
(database) in another object (databaseClient). Simple, right?
Anyway, I establish the binding like so:
[sineWaveView bind:@"connectedContact" toObject:databaseClient
withKeyPath:@"database.selectedShortRangeContact" options:nil];
This seems to only work one-way. When the view sets the property, it
gets set in the dictionary. However, when I update the value
directly in the dictionary, the view never gets a notification. It
is like the binding is one-way.
I'm assuming that your dictionary is in fact an NSMutableDictionary or
one of the CFDictionary variants. If this is the case then by itself
it's not sending out KVO notifications. You'll need to either wrap
that dictionary in some accessors that are in a class where automatic
KVO notifications are not disabled or one where you're specifically
issuing willChangeValueForKey: and didChangeValueForKey: methods
around you actually changing the value in the dictionary.
Another option if you can target Leopard is to look into using an
NSDictionaryController to bind to your dictionary. I've not done this
myself but I understand that it is meant to work specifically with
dictionaries treating them as an array of key/value pairs.
Ashley
_______________________________________________
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