NSFormatter, NSTextfield and bindings
NSFormatter, NSTextfield and bindings
- Subject: NSFormatter, NSTextfield and bindings
- From: Yann Disser <email@hidden>
- Date: Thu, 1 May 2008 15:51:06 +0200
I have a NSTextfield which is bound to some string-valued attribute.
It is set to update continuously and everything works fine.
As I only want to allow the user to enter numbers, I subclassed
NSFormatter and attached an instance to the NSTextField "formatter"
outlet in IB.
Now my attribute gets set exactly ONCE (?) - the very first time I
enter a valid character in the text field. I found the following with
google: http://www.cocoabuilder.com/archive/message/cocoa/2007/6/26/185130
and it seems that this behaviour might be intentional... (?!)
How can I obtain the desired behaviour of my text field with
continuous updates?
This is how my Formatter looks like:
@implementation StrictNumberFormatter
-(NSString*)stringForObjectValue:(id)anObject
{
if(![anObject isKindOfClass:[NSString class]])
return nil;
return anObject;
}
-(BOOL)getObjectValue:(id*)obj forString:(NSString*)string
errorDescription:(NSString**)error
{
if(obj)
*obj = string;
return YES;
}
-(BOOL)isPartialStringValid:(NSString*)partialString
newEditingString:(NSString**)newString
errorDescription:(NSString**)error
{
//return YES; //doesn't help either
if([partialString isEqual:@""])
return YES;
NSString* correct =
[[NSNumber numberWithInt:[partialString intValue]] stringValue];
return [correct isEqual: partialString];
}
@end
Thanks for your help,
Yann
_______________________________________________
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