I needed to add a UIKeyboardTypeDecimalPad keyboard to a decimal field, which can only be done programatically. I need the full code (I’m pretty new to Objective-C) to make a UIKeyboardTypeDecimalPad pop up when someone touches inside the text box. I’d also like to add the text field programmatically.
Basically, I need to add a text field with a UIKeyboardTypeDecimalPad keypad. Or, if possible, just the keypad to a text field made in Interface Builder.
Does anyone know a good tutorial for this or can anyone give me the full code themselves, and tell me where I need to put it (the .m or .h or what?)?
Thanks!
Update: As mentioned in the comment below, could I see example code for an app that does this?
To set the keyboard type to UIKeyboardTypeDecimalPad, just assign that value to the text field’s
keyboardTypeproperty.Adding a text field programmatically is only slightly more work:
UITextField *textField = [[[UITextField alloc] initWithFrame:frame] autorelease];to create it, then set any properties you need to set, and add it to the appropriate view withaddSubview:.In your view controller’s
viewDidLoadmethod is a good place for this sort of thing. Or if you’re loading a view without a controller from the nib, use the view’sawakeFromNibmethod.