• Home
  • Articles
  • UITextField: how to dismiss the Number Pad keyboard

UITextField: how to dismiss the Number Pad keyboard

Shahram Javeyvianote19.com
July 11, 2010

By default the Number Pad keyboard unlike the default keyboard does not have a “Done” button. I tried a number of different techniques to dismiss the keyboard, e.g., set the UITextField’s delegate to the ViewController and then add this method:

- (void)textFieldDidEndEditing:(UITextField *)textField
    [textField resignFirstResponder];

But this didn’t work. The method would get called, but the focus still remained in the UITextField. Instead, I chose to use the touches methods to dismiss the keyboard. This allows the user to touch anywhere outside of the text field to dismiss the keyboard. Here is a method that will dismiss the keyboard:

-(void)touchesBegan: (NSSet *)touches withEvent:(UIEvent *)event
       // do the following for all textfields in your current view
	[self.my_text_field_1 resignFirstResponder];
       // save the value of the textfield, ...