Redneys
Redneys

Reputation: 305

How to catch a change in UITextField text?

I have looked at all the similar questions and they are different than from what I am asking. I need to catch a change in the actual text in the UITextField, not just the state of editing. It will be a first responder when the view loads, and I need to know when text is entered so that I can enable "Next" in the navigation bar. Please help me if you can it's really holding me back in my project.

Addition: I am currently using - it doesn't work:

[textField addTarget:self action:@selector(textFieldDidChange)    forControlEvents:UIControlEventValueChanged];

Upvotes: 3

Views: 263

Answers (2)

Sergey Kalinichenko
Sergey Kalinichenko

Reputation: 727077

Implement UITextFieldDelegate protocol, and respond to the textField:shouldChangeCharactersInRange:replacementString: method.

- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)replacementStr {
    // Enable "Next" if you like what's entered in the replacementStr
}

Upvotes: 3

8vius
8vius

Reputation: 5836

Check the developer documents for UITextFieldDelegate, specifically this method

Upvotes: 0

Related Questions