If you have several text fields on the screen, and the keyboard pops up for each one when they are tapped, what if you want to programmatically hide the keyboard, or resign first responder, but you don’t know which textfield to send the resignFirstResponder message to? Is there a way to identify which object/textField should get this message?
If you have several text fields on the screen, and the keyboard pops up
Share
You could keep track of which text field is the first responder by either setting your view controller to be the delegate object of all text fields and then when your subclassed text fields gets the “
becomeFirstResponder” method call, tell your view controller which text field is the current one.Or, there’s a more blunt force approach which is a category extension to “
UIView“:which I got from this potentially very related question.