I also have implemented a UITextField for numeric (currency and percentage) input. Here is my experience: 1- I found the Number Pad keyboard fatally lacking due to omission of a decimal point character and a "Done" key. So use a Numbers and Punctuation keyboard. 2- I did not use a UIPickerView because I think this is too much work for the user. (This of course is debatable).
I used: -(BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string to disallow unwanted characters based on context and: - (void)textFieldDidEndEditing:(TVDecimalNumberTextField *)textField to ensure an in-range value. Hope this helps, Martin On 2011-07-26, at 6:43 AM, cocoa-dev-requ...@lists.apple.com wrote: > Message: 5 > Date: Mon, 25 Jul 2011 19:29:06 -0700 > From: Howard Siegel <hsie...@gmail.com> > Subject: Re: UITextField Questions > To: "cocoa-dev@lists.apple.com" <cocoa-dev@lists.apple.com> > Cc: Brooke Gravitt <bro...@gravitt.org> > Message-ID: > <camxiym8eatj9y2zefa+g3y9xweqpvhzj1duz5fro5+dk8i_...@mail.gmail.com> > Content-Type: text/plain; charset=ISO-8859-1 > > On Mon, Jul 25, 2011 at 18:31, Brooke Gravitt <bro...@gravitt.org> wrote: > >> On Mon, Jul 25, 2011 at 9:19 PM, Conrad Shultz >> <con...@synthetiqsolutions.com> wrote: >>> Take a look at UITextInputTraits to specify a numeric keyboard. (IIRC >> this can be done in IB too.) >>> >>> Take a look at UITextFieldDelegate's textFieldShouldEndEditing: method to >> perform validation of input. >>> >>> I should also point out that often a text field is not the most >> appropriate control for restricted numeric input. If you have a reasonably >> small finite set of input values, consider UIPickerView. If you have a >> finite range for input, consider UISlider. >>> >>> (Sent from my iPhone.) >>> >>> -- >>> Conrad Shultz >> >> Conrad, >> >> Thanks for the response! The fields in question are for setting a >> price and a percentage, respectively. They don't seem to fit into >> either category. I'll take a look at the UITextInputTraits && the >> delegate's textFieldShouldEndEditing method as well! >> >> Thanks! >> >> Brooke >> > > Brooke, > > You would likely be much better off using UIPickerViews, or a UIPickerView > and a UISlider as Conrad suggests. If the UISlider doesn't give you enough > selection precision, then use another UIPickerView. You use the UITextField > to keep the value for display purposes, but use the UIPickerViews for the > value selection. > > In order to use the UITextField for display and the UIPickerView for the > value > selection instead of the keypad you would need to create the UIPickerViews > and then set the UITextField inputView to the appropriate UIPickerView. When > the user taps in the text field, instead of a keypad coming up, the picker > view > will come up. You can also set the inputAccesoryView to a UIToolbar that > contains a "done" button so the picker view can be dismissed once the > user selects the value. > > The picker view for the percentage would contain 2 or 3 columns for the > decimal part (0 to 100) and as many columns for the fractional part as > needed. > > The picker view for the price would contain as many columns for the > dollar amount and 2 columns for the pennies. This assumes that the > price value isn't too outrageously large that you can't fit the dollar > amount > in to columns such that the picker view becomes too wide, and you can > get pretty wide if you drop the font size used for the columns. > > I can dig out some links to StackOverflow threads that I used to code up > exactly this type of user interface in an app that I am writing. > > - h > _______________________________________________ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) 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: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com