textField.keyboardType = UIKeyboardTypeDecimalPad;
[self.nameField becomeFirstResponder];If you want the keyboard to animate in after your view appears, you can call this in your
-viewWillAppear:
[textField resignFirstResponder];Otherwise, you can tell the enclosing view to end editing, and it'll figure out who is editing and tell them to resign:
[self.view endEditing: YES];
- (BOOL) textFieldShouldReturn: (UITextField *) textField { // Dismiss the keyboard. [self.view endEditing:YES]; return YES; }
- (BOOL) textField: (UITextField *) textField shouldChangeCharactersInRange: (NSRange) range replacementString: (NSString *) string { NSString *resultingString = [textField.text stringByReplacingCharactersInRange: range withString: string]; if (resultingString.length == 0) return YES; NSScanner *scanner = [NSScanner scannerWithString: resultingString]; float throwaway; BOOL scansFloat = [scanner scanFloat: &throwaway]; BOOL atEnd = [scanner isAtEnd]; return scansFloat && atEnd; } // shouldChangedCharacersInRanges(thanks to Frank Shearer, from a SO post)