Hello I have stumbled over a problem. My problem is as following:
When i use a function that dismisses the keyboard like this:
//Dismiss keyboard if in keyboard
let tap: UITapGestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(View.dismissKeyboard))
view.addGestureRecognizer(tap)
@objc func dismissKeyboard() {
view.endEditing(true)
}
It makes me not able to tap a cell in my tableview. It only responds if I longpress. My tableview is inside a uiviewcontroller. I would appreciate any suggestions.
This was a workaround for me:
extension UIViewController {
func hideKeyboardWhenTappedAround() {
let tap: UITapGestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(UIViewController.dismissKeyboard))
tap.cancelsTouchesInView = false
view.addGestureRecognizer(tap)
}
@objc func dismissKeyboard() {
view.endEditing(true)
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.