Search code examples
uitextfieldios7

UITextFieldTextDidChangeNotification iOS7 not fired


I'm using this piece of code to get informed about changing text of a UITextField.

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(textUpdated) name: UITextFieldTextDidChangeNotification object:self.inputValueField.text];

Works fine with iOS6 but is not getting called with iOS7. Any ideas?


Solution

  • Instead of NSNotifications, you can use UITextField's delegate to be notified about changing text.

    - (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
    

    From the documentation:

    Asks the delegate if the specified text should be changed.

    Discussion

    The text field calls this method whenever the user types a new character in the text field or deletes an existing character.