UITextField: how to dismiss the Number Pad keyboard

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, ...

2 Responses to “UITextField: how to dismiss the Number Pad keyboard”

  1. Olle Lind Says:

    Thanks for this post, REALLY helped!
    Bless you!

  2. richard Says:

    Thanks, worked great!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: