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: Preston Jackson <email@hidden>
- Date: Fri, 10 Apr 2009 08:55:58 -0600
Kyle,
Thanks for getting back to me about this! I really appreciate your help!
So, I do know that I should bind through a controller, but to pare
down the example to the simplest case, I omitted it.
My test application is very similar to yours. In fact, I even changed
it to do uppercase instead of length limiting, just to make it as
close as possible. Here's the entirety of my data model:
@implementation Model
- (NSString*)lengthLimitedString {
return lengthLimitedString;
}
- (void)setLengthLimitedString:(NSString*)string {
if (lengthLimitedString != string) {
[lengthLimitedString release];
lengthLimitedString = [string copy];
}
}
- (BOOL)validateLengthLimitedString:(id*)ioValue error:(NSError
**)error {
if (*ioValue == nil) {
return YES;
}
*ioValue = [*ioValue uppercaseString];
return YES;
}
@end
The problem remains that the contents of the NSTextField do NOT update
to the capitalized value in the model, UNTIL the text field resigns
first responder. I would like the NSTextField to always have what it
represented in the model (which is what I thought "Continuously
Updates Value" settings was for).
Can you verify that the text in your NSTextField updates immediately,
and not just when you are done editing?
Thanks!
Preston
On Apr 9, 2009, at 10:52 PM, Kyle Sluder wrote:
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