0

Is there a way to dismiss keyboard without referencing the UITextField outlet one by one?

rmaddy
  • 307,833
  • 40
  • 508
  • 550
iqbalzas
  • 717
  • 7
  • 11

2 Answers2

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,589
  • 2
  • 19
  • 33
-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)
}