iPhone: TextField custom textDidChange action
While working on a project, I came across a requirement where I was required to fire an action on textfield text change. I did not find any method that apple provides like it does for searchbar text change. With some research on google, I went ahead and created a custom method which was then added on textfield event change namely UICOntrolEventEditingChanged.
This was what I did to make it work.
In ViewDidLoad, I added the following code:
[myTextfield addTarget:self action:@selector(textFieldDidChange:) forControlEvents:UICOntrolEventEditingChanged];
Here I am attaching ‘textFieldDidChange’ method which will be called once the text in the myTextfield changes. I named it like this to make it sound more like the method for searchbar textchange method.
The actual method is:
-(void)textFieldDidChange {
// whatever you wanted to do
someLabel.text = myTextfield.text;
}