5

I am using in my programatically made uitextfield

-(BOOL)textFieldShouldEndEditing:(UITextField *)textField
{
[textField resignFirstResponder];
return YES;
}

to catch an event that my textfield is done editing.In events that i change the focus from one text field to another or press return ,the event is fired,but if i am in a textfield and click another uicontrol like a button from it ,this method is not fired.what is wrong here...i need to catch every event when a user has done editing a textfield. i tried with textfielddidendediting too but this event is missed..How to overcome this

3 Answers 3

7

when you click on button .write code in - (IBAction) method

[yourTextField resignFirstResponder]; then those method will get called.

 - (IBAction) yourBtnClicked:(id)sender
 {
   [textField resignFirstResponder];
 }
2
  • 1
    Ok, but how to catch which is the textField if you are using custom UITableViewCell?
    – new2ios
    Aug 3, 2015 at 16:01
  • Declare your UITextField variable as class parameter
    – Kaptain
    Apr 12, 2016 at 8:57
1

What happens here is that when you are editing a textfield and then you click on a UIButton or anything else then the delegate methods for UITextfield will not be called.

For that, you'll have to write the code for that textfield inside the code for that button.

All you need is,

   //inside your btn action
   - (IBAction) btnPressed : (id) sender
   {
        [self textFieldDidEndEditing:myTextField];
        //remaining code goes here....
   }
0

The problem is likely to be that DidEndEditing will not fire, because your text field is still the first responder even after the button is clicked.

You could set the first responder when your button is clicked, and then release first responder. Then, regardless of which text field was last edited before clicking the button, it's DidEndEditing event will fire.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.