Repaz Kung
Repaz Kung

Reputation: 43

Hide keyboard by pressing button

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.

Upvotes: 1

Views: 4200

Answers (2)

Rubaiyat Jahan Mumu
Rubaiyat Jahan Mumu

Reputation: 4127

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.

Upvotes: 1

Volodymyr
Volodymyr

Reputation: 1205

[self.view endEditing:YES]

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

self.view.endEditing(true)

Upvotes: 4

Related Questions