Re: Problem with NSNumberFormatter - no result even after searching the complete cocoa mamasam archive
Re: Problem with NSNumberFormatter - no result even after searching the complete cocoa mamasam archive
- Subject: Re: Problem with NSNumberFormatter - no result even after searching the complete cocoa mamasam archive
- From: Bill Cheeseman <email@hidden>
- Date: Sun, 06 Jul 2003 09:14:56 -0400
From the sound of things, you might have missed two things: (1) It isn't
enough to create and attach a number formatter; you also have to implement a
method in your code to catch and handle any errors the formatter reports.
(2) The built-in number formatter in IB doesn't do on-the-fly formatting and
filtering; it only tests what the user already typed into the text field,
when the user clicks out or tabs out of the text field or clicks an OK
button.
(1) The documentation for the delegate methods you have to implement to
catch formatter errors starts on your computer at
/Developer/Documentation/Cocoa/TasksAndConcepts/ProgrammingTopics/DataFormat
ting/index.html. I believe there is lots of other documentation on these
methods.
(2) You have to write a custom formatter to do on-the-fly filtering of the
user's typing. Once you get the hang of it, it is pretty easy to prevent the
user from entering non-numeric characters, or more than a specified number
of characters, and to beep at the user or put up an alert sheet if the user
tries to do so. The documentation for creating custom formatters is on your
computer starting at
/Developer/Documentation/Cocoa/TasksAndConcepts/ProgrammingTopics/DataFormat
ting/index.html. There are several complete examples, including on-the-fly
filters, in my book "Cocoa Recipes for Mac OS X: The Vermont Recipes," and
no doubt elsewhere, too.
on 03-07-06 8:48 AM, Poornima Ranganath at email@hidden wrote:
>
I have a TextField which should allow ONLY numbers
>
with maximam of 4 digits.
>
>
i use a number formatter on the text field[have drag
>
and dropped it on NSTextField].
>
>
i want the user to enter any number between 1000 to
>
9999 ONLY.
>
>
In the Number formatter, i enter
>
POSITIVE - ####
>
Zero-
>
NEGETIVE - -####
>
Miminum - 1000
>
Maximam - 9999.
>
>
[I have unchecked the Add 1000's seperator]
>
even check this switch does no help.
>
>
when i enter values into the text field within the
>
valid range,it does not loose focus AND even when i
>
enter junk it does not loose focus.
>
I can enter any junk and click on a "Ok" button and go
>
ahead.. I don't want this to happen.
>
I must not be able to click on "Ok" button nor should
>
the text field loose focus when any entry is made in
>
it unless it is valid.
>
>
What wrong am i doing??
>
>
I have gone through all the documentation on creating
>
number formatters, and searched the cocoa mamasam
>
archive without much results.
>
>
Can u pls hlp me?
--
Bill Cheeseman - email@hidden
Quechee Software, Quechee, Vermont, USA
http://www.quecheesoftware.com
The AppleScript Sourcebook -
http://www.AppleScriptSourcebook.com
Vermont Recipes -
http://www.stepwise.com/Articles/VermontRecipes
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.