• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: NSFormatter, NSTextfield and bindings
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSFormatter, NSTextfield and bindings


  • Subject: Re: NSFormatter, NSTextfield and bindings
  • From: Yann Disser <email@hidden>
  • Date: Fri, 2 May 2008 15:31:11 +0200

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

_______________________________________________

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


References: 
 >NSFormatter, NSTextfield and bindings (From: Yann Disser <email@hidden>)

  • Prev by Date: Re: Disabling screen turning off
  • Next by Date: CALayer backgroundFilters can't cope with animated backgrounds?
  • Previous by thread: NSFormatter, NSTextfield and bindings
  • Next by thread: Re: Xcode debugger quality
  • Index(es):
    • Date
    • Thread