Re: KVO Question -- Really Simple for Pros
Re: KVO Question -- Really Simple for Pros
- Subject: Re: KVO Question -- Really Simple for Pros
- From: "Owen Yamauchi" <email@hidden>
- Date: Fri, 27 Jun 2008 23:21:49 -0700
On Fri, Jun 27, 2008 at 10:20 PM, Alex Wait <email@hidden> wrote:
> But I was sure since I have a firstName method and a setFirstName method it
> would update the textField. I have used IB to bind the value of the
> textField to the value of the person object and that works when I edit the
> textfield (yay). So I know I have the proper methods. I think.
If you've set the binding in IB, there's no need to write any code.
The problem you're running into with this code is that you're
registering the text field as an observer of changes in the firstName
property, but the text field has no idea what it should do when it
receives notification of changes. Changing firstName generates a KVO
notification (two, actually) which causes a
-observeValueForKeyPath:ofObject:change:context: message to be sent to
the text field, but how does the text field know what this means? The
obvious thing (to you) is to change its text, but there's any number
of other things you can bind in a text field.
If you want to set up the binding in code, use
-bind:toObject:withKeyPath:options:.
Owen
[forgot to reply-all before]
_______________________________________________
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