I am trying to use UIControlEventEditingChanged to register for updates whenever the text changes in my UITextField occurs. However something really odd is happening, the handlefieldTextChanged is only called when I delete a character in my UITextField and not when I type something.
This is my code:
[textField setDelegate:self];
[textField addTarget:self action:@selector(handlefieldTextChanged) forControlEvents:UIControlEventEditingChanged];
- (IBAction)handlefieldTextChanged {
NSLog(@"handleChange");
}
Now the handlefieldTextChanged is declared in the header file and is an IBAction just to see if connecting it in Interface Builder would fix anything but it doesn't.
Anyway what is causing this to happen? Whatever I try I can't get true textfield changed updates.
Edit1:
- (NSString *)removeBadWordsFromString:(NSString *)string {
for (NSString * word in badWords){
string = [string stringByReplacingOccurrencesOfString:word withString:@""
options:NSCaseInsensitiveSearch range:NSMakeRange(0, string.length)];
}
return string;
}
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {
[textField setText:[self removeBadWordsFromString:[NSString stringWithFormat:@"%@%@", textField.text, string]]];
return (string.length == 0);
}