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?
The Problem is, that you are passing the wrong object. You are passing the NSString in your UITextField, but should passthe UITextField itself.
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(textUpdated)
name: UITextFieldTextDidChangeNotification
object:self.inputValueField];
This should work.
Better using NSNotificationCenter. Here is a code snippet from a passcode managing section of an app.
Initialize NSNotificationCenter in viewDidLoad
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(textDidChange:) name: UITextFieldTextDidChangeNotification object:nil];
then declare its method textDidChange:
- (void)textDidChange:(NSNotification*)notification
{
UITextField *textField = (UITextField *)[notification object];
DBG(@"%@", textField.text);
if(textField == self.txtPasscode1 && textField.text.length == 1)
{
[self.txtPasscode2 becomeFirstResponder];
}
if(textField == self.txtPasscode2 && textField.text.length == 1)
{
[self.txtPasscode3 becomeFirstResponder];
}
if(textField == self.txtPasscode3 && textField.text.length == 1)
{
[self.txtPasscode4 becomeFirstResponder];
}
if(textField == self.txtPasscode4 && textField.text.length == 1)
{
[self.txtPasscode1 becomeFirstResponder];
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With