Re: Programmatically setting the value of a bound TextField
Re: Programmatically setting the value of a bound TextField
- Subject: Re: Programmatically setting the value of a bound TextField
- From: Ricky Sharp <email@hidden>
- Date: Wed, 1 Mar 2006 09:22:03 -0600
On Mar 1, 2006, at 8:29 AM, Felix Franz wrote:
In my program I have NSTextField bound to an object using the
"value"-Binding.
I would like to test the functionality in a unit-test. I tried
using setStringValue:
of the NSTextField but the bound object is not updated. Do I have
to call some
methods before/after changing the value?
For example:
// setup:
NSTextField* textField = [[NSTextField alloc] initWithFrame:
NSMakeRect(0,0,100,20)];
id person = [Person personWithName: @"foo"]; // person has "name"
NSObjectController* controller = [[NSObjectController alloc]
initWithContent: person];
[textField bind: @"value"
toObject: controller
withKeyPath: @"selection.name"
options: nil]
// try it out:
NSString* newName = @"bar";
[textField setStringValue: newName];
Instead of using setStringValue: here, try using setValue: instead.
After all, you are binding to "value". setValue: should have in its
implementation the steps to notify bound objects of the change.
STAssertEqualObjects( [person valueForKey:@"name"], newName, nil);
// this fails
___________________________________________________________
Ricky A. Sharp mailto:email@hidden
Instant Interactive(tm) http://www.instantinteractive.com
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden