Resigning First Responder for multiple UITextFields

Kritanshu_iDev picture Kritanshu_iDev · Jul 14, 2011 · Viewed 12.9k times · Source

There is an application in which I am generating multiple UITextFields dynamically. I want to resign first responder whenever the UITextFields are not selected (touch outside the UITextField). How can I know that of which UITextField I have to resign first responder? Please specify any other way beyond the 'tag' concept because I have tried that. Please suggest the right direction. Thanks in advance.

Answer

benzado picture benzado · Feb 10, 2012

Don't call resignFirstResponder; call endEditing:!

Call endEditing: on any view above the text fields in the view hierarchy. It will locate the first responder and ask it to resign. Use endEditing:YES to force it or endEditing:NO to let the text field's delegate decide if it should end editing (useful if you are validating input).