Re: NSTextField and bindings
Re: NSTextField and bindings
- Subject: Re: NSTextField and bindings
- From: Steve Sims <email@hidden>
- Date: Tue, 4 May 2004 14:48:26 -0400
On 4 May 2004, at 12:38, Fritz Anderson wrote:
The Key-Value Validation documentation says, "Note: Key-value coding
does not perform validation automatically, it is your applications
responsibility to invoke the validation methods. Also, an
implementation of -set<Key>: for a property should never call the
validation methods."
This would seem to make KVV useless for your (or many) purposes, but
the value binding on the text field has a "Validate Immediately"
switch that does in fact automatically call KVV on the value.
Hmmm... Interesting. This would indeed seem to be the way to do
things, so I just wrote a validator as follows:
- (BOOL)validateText:(id *)ioValue error:(NSError **)outError
{
if ((*ioValue == nil) || ([*ioValue length]==0)) {
*ioValue = text;
}
return YES;
}
...plus of course I got rid of the check in my setText for zero length
strings.
However this just seems to give me the same results. When I put
breakpoints in my validator and setter methods I see that they are both
getting called when one would expect them to, and they seem to do their
job OK. My model ends up with valid data, which is good, however my UI
does not reflect the model, which is not so good. Slapping in
will/didChangeValueForKey calls also makes no difference.
Unless you, me, or somebody else comes up with something to solve this
one it looks like I may have to revert to an old-fashioned non-bindings
way of setting this value...
Steve
-- F
On 4 May 2004, at 10:45 AM, Steve Sims wrote:
I have an NSTextField in my app and I'm using bindings to hook it up
to my data model. Now it's important that this text field keeps a
value, and is not set to an empty string. With that in mind I wrote
a quick setter method as follows:
- (void)setText:(NSMutableString *)newText {
if ((text != newText) && ([newText length]>0)) {
[text release];
text = [newText copy];
}
}
Now whilst this ensures that within my data model the text field
keeps its value when an empty string is attempted to be entered in
the UI the UI does not reflect this: the text field on screen stays
empty.
I tried adding in [self willChangeValueForKey:@"text"]; and [self
didChangeValueForKey:@"text"]; calls at the beginning and end of this
setter (outside the if) since I thought that may force the UI to
update, but it didn't work.
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.