• 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: NSNumberFormattter not working
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSNumberFormattter not working


  • Subject: Re: NSNumberFormattter not working
  • From: Ken Tozier <email@hidden>
  • Date: Thu, 12 Jul 2007 16:09:06 -0400


On Jul 12, 2007, at 3:59 PM, Erik Buck wrote:

I think that all you need to do is implement an NSFormatter subclass with the following method and no more: (typed in mail)

  - (BOOL) isPartialStringValid:(NSString *) partialString
       newEditingString:(NSString **) newString
       errorDescription:(NSString **) error
{
   NSLog(@"entered KIntegerFormatter:isPartialStringValid");
   NSAssert(NULL != newString, @"Invalid newString argument");

NSRange validRange = [(*newString) rangeOfCharacterFromSet: [NSCharacterSet decimalDigitCharacterSet]];
*newString = [(*newString)substringWithRange:validRange];
return YES;
}


Then use this formatter anywhere you want only decimal digits entered. Leading zeros are fine.

Just tried your suggestion and got a crash stating "no stringForObjectValue method found" so I guess that is necessary. (The documentation says you need to override all 3 of these "stringForObjectValue," "getObjectValue," "attributedStringForObjectValue.")


At this point, I'm going to throw in the towel on this one. I've been trying to get this working since 6:30 a.m. and it's now 4:10 in the afternoon. It's way more trouble than it's worth. I'l just pop up a dialog and erase what the user typed.

Thanks all for your help

Ken


_______________________________________________

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:
40comcast.net


This email sent to email@hidden

_______________________________________________

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: 
 >Re: NSNumberFormattter not working (From: Erik Buck <email@hidden>)

  • Prev by Date: Re: NSNumberFormattter not working
  • Next by Date: Re: NSNumberFormattter not working
  • Previous by thread: Re: NSNumberFormattter not working
  • Next by thread: Re: NSNumberFormattter not working
  • Index(es):
    • Date
    • Thread