• 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: Limiting NSTextField to numbers?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Limiting NSTextField to numbers?


  • Subject: Re: Limiting NSTextField to numbers?
  • From: Alex Kac <email@hidden>
  • Date: Wed, 21 Jan 2009 14:56:34 -0600

Use the delegate I gave you and format it there. UITextField does not accept formatters. Look at the docs - all the answers are right there. Here is how I do it:

Type in the class in the dev doc window. Set it to only show the iPhone OS 2.2 docs. Contains. Full Text. It shows me immediately the class reference and the delegates. Usually one or the other will answer what I'm looking for. If not, sometimes a sample will.

The Tasks sub-pane in the reference is usually very good. In this case you see clearly that textField:shouldChangeCharactersInRange:replacementString: tells you when a user types in a character and from there you can do what you need.

On Jan 21, 2009, at 2:48 PM, Brooke Gravitt wrote:

On Wed, Jan 21, 2009 at 3:31 PM, Nick Zitzmann <email@hidden> wrote:

You could always attach the formatter manually, like this: (written in Mail,
untested, use at your own risk, and all that)


- (void)awakeFromNib
{
NSNumberFormatter *formatter = [[[NSNumberFormatter alloc] init]
autorelease];


// Normally you'd have to set the formatter behavior here, but this
isn't necessary on the iPhone/iPod
[formatter setNumberStyle:NSNumberFormatterDecimalStyle];
[someTextField setFormatter:formatter];
}


Nick Zitzmann
<http://www.chronosnet.com/>

This was what I was thinking I might do.

Perhaps I'm coming at this backwards as well - I should probably just
display the number pad and automagically insert the decimal place.

What's a good strategy for forcing the text field to always have the
last two digits as  cents?

i.e.

Text field looks like : $ 0.00

as user punches 12345 it would update like this -

$ 0.01
$ 0.12
$ 1.23
$ 12.34
$ 123.45

Make sense?
_______________________________________________

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

Alex Kac - President and Founder Web Information Solutions, Inc.

"In the Country of the Blind, the one-eyed man is king."
--Desiderius Erasmus





_______________________________________________

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: 
 >Limiting NSTextField to numbers? (From: Brooke Gravitt <email@hidden>)
 >Re: Limiting NSTextField to numbers? (From: "I. Savant" <email@hidden>)
 >Re: Limiting NSTextField to numbers? (From: Brooke Gravitt <email@hidden>)
 >Re: Limiting NSTextField to numbers? (From: Andy Lee <email@hidden>)
 >Re: Limiting NSTextField to numbers? (From: Brooke Gravitt <email@hidden>)
 >Re: Limiting NSTextField to numbers? (From: Nick Zitzmann <email@hidden>)
 >Re: Limiting NSTextField to numbers? (From: Brooke Gravitt <email@hidden>)

  • Prev by Date: Re: Limiting NSTextField to numbers?
  • Next by Date: Re: Log4Cocoa
  • Previous by thread: Re: Limiting NSTextField to numbers?
  • Next by thread: Re: Limiting NSTextField to numbers?
  • Index(es):
    • Date
    • Thread