Is there a way to dismiss keyboard without referencing the UITextField outlet one by one?
Asked
Active
Viewed 289 times
2 Answers
0
Swift 3.x Use this:
self.view.endEditing(true) //when you are using a view
self.tableView.endEditing(true) //when you are a table-view
The view will resign the keyboard from all child. You call it when a user touches the table or view.

Salman Ghumsani
- 3,647
- 2
- 21
- 34
-
if it is in inside the tableview or scrollview your answer will work ..? – Anbu.Karthik Sep 22 '17 at 13:36
-
no , if it is in scrollview then use `self.scrollview.endEditing(true)` – Anbu.Karthik Sep 22 '17 at 13:37
-
see this for e.g https://stackoverflow.com/questions/2321038/dismiss-keyboard-by-touching-background-of-uitableview – Anbu.Karthik Sep 22 '17 at 13:38
-1
This is how I use it, when allowing the user to tap on the view to dismiss the keyboard
let tap = UITapGestureRecognizer(target: self, action: #selector(self.handleTap))
view.addGestureRecognizer(tap)
And than create a function like below
@objc func handleTap() {
view.endEditing(true)
}