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 (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]

Reply via email to