sujith1406
sujith1406

Reputation: 2822

textfieldDidEndEditing method is not fired when i end editing, and choose another uicontrol than textfield

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

Upvotes: 5

Views: 7612

Answers (3)

Johan Franzén
Johan Franzén

Reputation: 2424

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.

Upvotes: 0

mayuur
mayuur

Reputation: 4746

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....
   }

Upvotes: 1

PJR
PJR

Reputation: 13180

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

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

 - (IBAction) yourBtnClicked:(id)sender
 {
   [textField resignFirstResponder];
 }

Upvotes: 7

Related Questions