I use a UITableView for a user/password login control. Right now it’s the only control on the view, along with a login button. When i click inside, the text edit content becomes active, the keyboard pops up and I can type. however there is no way to stop the editing. I’d like to click outside on the white area of my UIView so that the focus is taken away from the text editors inside my UITableVIew and the keyboard becomes invisible again.
How do I do that?
In
viewDidLoadmake your view controller listen to keyboard notifications and create a tap recognizer which will receive all events outside of your tableView:Then in the notification methods for the keyboard add and remove the gesture recognizer from your view.
In the action method of your gesture recognizer you resign all first responders to dismiss the keyboard:
Don’t forget to end listening to the keyboard notifications at some point: