Re: Trying To Understand Bindings
Re: Trying To Understand Bindings
- Subject: Re: Trying To Understand Bindings
- From: "Bridger Maxwell" <email@hidden>
- Date: Sat, 13 Dec 2008 00:40:44 -0700
Woops, I posted some wrong code which might confuse the issue. This is the
real code that binds the view to the dictionary, but only sends
notifications from the view to the dictionary (and not the other way
around).
[databaseClient bind:@"database.selectedShortRangeContact"
toObject:sineWaveView withKeyPath:@"connectedContact" options:nil];
Thank You,
Bridger Maxwell
On Fri, Dec 12, 2008 at 11:19 PM, Bridger Maxwell <email@hidden>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 Googled around, and couldn't quite understand why this was, but
> decided that perhaps it was because I wasn't using NSObjectController. On
> this site, http://rails.wincent.com/wiki/Cocoa_bindings_notes, Scott
> Anguish says "Alway, always use a controller," so I thought it was worth a
> shot.
>
> Here is the code I used to make the NSObjectController, and then bind the
> view to the object.
>
> databaseController = [[NSObjectController alloc]
> initWithContent:databaseClient];
> [databaseController bind:@"content.database.selectedShortRangeContact"
> toObject:sineWaveView withKeyPath:@"connectedContact" options:nil];
>
> This is where I am stuck. It sets up the observing just fine. I know this,
> because when I enter the wrong keyPath I get an error. For example,
>
> [databaseController bind:@"content.wrongKey.selectedShortRangeContact"
> toObject:sineWaveView withKeyPath:@"connectedContact" options:nil];
>
> causes the following output:
>
> [<SCPushDatabaseClient 0x1033470> valueForUndefinedKey:]: this class is not
> key value coding-compliant for the key wrongKey.
>
> So, I set it up correctly and I don't get that error. However, even when it
> is set up correctly, I get the following error when I the view changes the
> value:
>
> [<NSObjectController 0x1062fa0> setValue:forUndefinedKey:]: this class is
> not key value coding-compliant for the key
> content.database.selectedShortRangeContact.
>
> So, why isn't NSObjectController key value coding-compliant for a keyPath
> beginning in "content"? What am I doing wrong here?
>
> Thank You,
> Bridger Maxwell
>
_______________________________________________
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