Re: Setting Min, MAx and range of characters for NSTextField
Re: Setting Min, MAx and range of characters for NSTextField
- Subject: Re: Setting Min, MAx and range of characters for NSTextField
- From: Kyle Sluder <email@hidden>
- Date: Fri, 10 Apr 2009 00:52:21 -0400
On Thu, Apr 9, 2009 at 7:02 PM, Preston Jackson
<email@hidden> wrote:
> Anyone have any ideas on this?
First, you typically don't bind views directly to the model. You
instead bind them through a controller.
I did a quick test, however, in which I did bind an NSTextField
straight to my model. I created a simple NSObject subclass with an
NSString property called "uppercaseString". I also implemented
-validateUppercaseString:error: to always convert the string to
uppercase. I then bound an NSTextField to this property, and turned
on "Validates Immediately." It works like a charm.
Here is my implementation of -validateUppercaseString:error:, for reference.
- (BOOL)validateUppercaseString:(id *)newValue error:(NSError **)error
{
if(*newValue == nil)
return YES;
*newValue = [*newValue uppercaseString];
return YES;
}
How does your implementation differ? Are you perhaps mutating the
*newValue instead of returning a new object, as the documentation says
you must? http://developer.apple.com/DOCUMENTATION/Cocoa/Conceptual/KeyValueCoding/Concepts/Validation.html#//apple_ref/doc/uid/20002173-168285
--Kyle Sluder
_______________________________________________
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