Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 690
sujith1406 Avatar asked Aug 23 '11 09:08

sujith1406


2 Answers

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

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

 - (IBAction) yourBtnClicked:(id)sender
 {
   [textField resignFirstResponder];
 }
like image 90
PJR Avatar answered Nov 14 '22 12:11

PJR


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....
   }
like image 20
mayuur Avatar answered Nov 14 '22 12:11

mayuur