1

how can I hide the keyboard by simply pressing a button? For example when you want to type something into a textField and the keyboard should disappear after pressing a button which calls an action.

Repaz Kung
  • 43
  • 1
  • 8
  • try calling `endEditing:` on your textfield when you want to hide the keyboard – BenJammin Sep 22 '16 at 19:04
  • Possible duplicate of [How to dismiss keyboard iOS programmatically](http://stackoverflow.com/questions/18755410/how-to-dismiss-keyboard-ios-programmatically) – jose920405 Sep 22 '16 at 22:48

2 Answers2

4
[self.view endEditing:YES]

Paste it in action handler of your controller. Or for Swift:

self.view.endEditing(true)
Volodymyr
  • 1,165
  • 5
  • 16
1

For objective c :

[_nameOfYourTextField resignFirstResponder];

If you have multiple textViews in the view then

[self.view endEditing:YES];

For swift:

nameOfYourTextField.resignFirstResponder()

If you have multiple textViews in the view then

self.view.endEditing(true)

Put these statements in your action method.

Rubaiyat Jahan Mumu
  • 3,887
  • 1
  • 33
  • 35