Daniel M. Daniel M. - 1 year ago 57
iOS Question

iOS SDK: Dismiss keyboard when a button gets clicked?

How can I dismiss the keyboard when the user clicks a button?
A short example for a better understanding: the user edits some text in some textfields and at the end he doesn't click "Done" or smething else on the keyboard, but he clicks on an button "Save" while the keyboard is still shown. So, how can I now dismiss the keyboard?

Thx. Regards, Daniel

Answer Source

in button action write,

if([textField isFirstResponder]){
  [textField resignFirstResponder];

if there are more textfields get the current textfield reference everytime while editing started, and resign its responder in button action.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download