• 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 Question
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: NSFormatter Question


  • Subject: RE: NSFormatter Question
  • From: Ulai Beekam <email@hidden>
  • Date: Sun, 24 May 2009 19:51:49 +0000
  • Importance: Normal

You're right, you can't edit the formatter's error in control:didFailToFormatString:errorDescription: because the error description has already been determined.


You need to override the getObjectValue:forString:errorDescription: method of NSFormatter to set a custom error description.


As for disallowing invalid characters while typing, which is probably what you want (in addition to an NSBeep() perhaps), you should look at the isPartialStringValid:newEditingString:errorDescription: method in NSFormatter.



----------------------------------------
> From: email@hidden
> To: email@hidden
> Date: Sun, 24 May 2009 13:30:30 -0500
> CC:
> Subject: NSFormatter Question
>
> This is a newbie question, my apologies if it has been discussed in
> the past. I haven't been programming on a Mac since the System 7 days
> and trying to catch up with OS X and Cocoa...
>
> I have text field bound to an NSObjectController with an
> NSNumberFormatter to ensure that there are only integer numbers
> entered. Whenever I leave the field blank or enter invalid characters,
> I get a very generic error message "Formatting Error". I'd like to
> customize that error message with a hint for the user which values are
> valid (similar to the message I get in the standard print dialog when
> entering zero copies), but I haven't found a way to do so, except for,
> perhaps, subclassing NSNumberFormatter. I had a look at -
> control:didFailToFormatString:errorDescription:, but noticed that the
> error description is not a mutable string, therefore I cannot pass
> back a modified error message. Is there a way to customize the error
> message without having to create a new subclass of NSNumberFormatter
> for each field with a different format?
>
> On a related topic, if I set "Validates Immediately" on the binding of
> that particular field, I was expecting to be stopped in my tracks as
> soon as I enter, say, a letter instead of a number, but nothing
> happens. It seems like the setting of the Validates Immediately flag
> doesn't have any impact on the behavior. Am I missing something here?
> _______________________________________________
>
> 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

_________________________________________________________________
Show them the way! Add maps and directions to your party invites.
http://www.microsoft.com/windows/windowslive/products/events.aspx_______________________________________________

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

  • Follow-Ups:
    • Re: NSFormatter Question
      • From: Dietmar Kuttelwascher <email@hidden>
References: 
 >NSFormatter Question (From: Dietmar Kuttelwascher <email@hidden>)

  • Prev by Date: Can't understand this build error
  • Next by Date: Re: Can't understand this build error
  • Previous by thread: NSFormatter Question
  • Next by thread: Re: NSFormatter Question
  • Index(es):
    • Date
    • Thread