iOS: Hide keyboard when the user tapped else where
In certain circumstances (i.e. The table row to edit.), we do want the keyboard to be hide in order to improve user experience
In YourViewController.m
1 | - (void)viewDidLoad |
In this case we are talking about the first section first row contain a UITextField which allows user to edit.
You want the keyboard to keep appear if the user tap back the row which they’re editing, so just return
and end the function. Otherwise, the keyboard will be hide (i.e. make the firstRowTextField
lost focus)
UITapGestureRecognizer
is like an event listener to listen for Tap event, if the Tap event occurred, hideKeyboard
will be triggered and passed itself as an argument. The hideKeyboard
will then act accordingly.