Search code examples
variablesuitextfieldfirst-responder

UITextField - Action on resignFirstResponder -- possible?


I have created a form that has a number of text fields that save to NSStrings that are then used deeper in the app.

Currently, if you hit the return key (done) on the GUI keyboard, the keyboard is dismissed, and the data in the text field is saved to its NSString. Likewise, if the background is touched the same occurs.

However, if I touch another text field, without doing one of the above first, the variable is not saved. Is there a way to do this? Perhaps a way to perform an action when a specific text field release firstresponder?


Solution

  • The best solution for your issue is just to use the

    -(void)textFieldDidEndEditing:(UITextField *)textField 
    

    And then you can just access the textField and store the textFields text in the appropriate string every time focus is lost.