https://stackoverflow.com/questions/34835132/how-to-hide-keyboard-in-uitableviewcontroller
If you want to override -touchesBegan:withEvent: for your UITableView, you will need to subclass UITableView.
touchesBegan:withEvent: is only sent to subclasses of UIView. You are implementing touchesBegan:withEvent: in your controller.So, it won't work...
You can solve this with UIGestureRecognizer like this -
let tap = UITapGestureRecognizer(target: self, action: Selector("handleTap:"))
tap.delegate = self
self.view.addGestureRecognizer(tap)
Then implement the handler -
func handleTap(sender: UITapGestureRecognizer? = nil) {
// handling code
self.view.endEditing(true)
}
Now call handleTap() at relevant position.