NSNumberFormatter and blank text fields
NSNumberFormatter and blank text fields
- Subject: NSNumberFormatter and blank text fields
- From: Bill Cheeseman <email@hidden>
- Date: Thu, 28 Jun 2001 10:23:42 -0400
I have used Interface Builder to attach an NSNumberFormatter instance to a
text field. The formatter is set up to accept a range of values between, say
75 and 155. It works perfectly, rejecting all out-of-range values -- with
these two exceptions:
(1) The formatter is not invoked if the user deletes the contents of the
field and clicks Enter, thus attempting to enter a blank value. I traced
execution to confirm that the formatter is not invoked in this situation.
(2) The formatter also isn't invoked when "0.0" is entered, although it is
invoked if "0" is entered. (The text field is designed to hold a float, but
I don't see how this pertains.)
In both cases, after hitting Enter, the field holds an out-of-range floating
point value, 0.00000000....
Am I supposed to do something more than Interface Builder allows me to do to
prevent blank or 0.0 entries, or is this a bug in NSNumberFormatter?
If it's a bug, what is the best workaround? I have settled upon NSControl's
control:shouldEndEditing: method. Is there anything better, or more
traditional?
--
Bill Cheeseman - email@hidden
Quechee Software, Quechee, Vermont, USA
The AppleScript Sourcebook - www.AppleScriptSourcebook.com
Vermont Recipes - www.stepwise.com/Articles/VermontRecipes