On Fri, Jun 27, 2008 at 11:29 PM, Alex Wait <[EMAIL PROTECTED]> wrote:
> I've read what you said but I don't know what to do still.
>
> Do I need to implement the method? the -observeValueForKeyPath
>>
>> :ofObject:change:context: method?

No. NSTextField implements this already. See below.

> I am not having trouble with bindings. They seem to be working ok.
>
> What I need to know is what I need to add to get the text field to update
> whenever firstName is changed. I want it to set
> the value of its string value to the string.

Then setting the binding in IB should be enough. You shouldn't need to
write any code.

> If not, why not just do it in the action method? Would I do it the KVO
> method so whenever I updated it, even outside of the message,
> it would get updated? Also where do I put the -observeValueForKeyPath
>>
>> :ofObject:change:context: method?
>
>
> "but how does the text field know what this means?" how do I tell it? that's
> what I've been trying to ask all along.

Somewhere, there must be a call to
-bind:toObject:withKeyPath:options:. That happens under the hood when
you set the binding in IB. This is how the text field knows what KVO
notifications mean.

Think of it like this. When something (your code, or the nib loader)
calls [textField bind:@"value" toObject:person
withKeyPath:@"firstName" ...], that is telling the text field, "hey,
when you get a KVO notification from person that its value for the key
path 'firstName' has changed, that means you need to change your
value". The text field writes this down on a list of things to do when
it gets a KVO notification. Only when this call has taken place can
the text field know what to do with a KVO notification; when
-observeValueForKeyPath:ofObject:change:context: gets called as a
result of a KVO notification, the text field will check its list of
things to do, and see that it needs to update its value (if indeed the
notification was about the right object and key path).

Owen
_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]

Reply via email to