Skip navigation.
 
mlRe: NSFormatter, NSTextfield and bindings
FROM : Yann Disser
DATE : Fri May 02 15:31:11 2008

Ok, I found my problem myself. In

> -(BOOL)getObjectValue:(id*)obj forString:(NSString*)string
>      errorDescription:(NSString**)error
> {
>  if(obj)
>    *obj = string;
>  return YES;
> }


the line
>    *obj = string;

needs to be replaced with
      *obj = [NSString stringWithString:string];

I always assume that gc takes care of all my memory managing needs...

I hope this helps someone in the future ^^

Yann

On 1. May 2008, at 15:51, Yann Disser wrote:

> 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

Related mailsAuthorDate
mlNSFormatter, NSTextfield and bindings Yann Disser May 1, 15:51
mlRe: NSFormatter, NSTextfield and bindings Yann Disser May 2, 15:31