have the following:
// watch the fields
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(handleTextChange:)
name:UITextFieldTextDidChangeNotification
object:textField1];
and then:
-(void) handleTextChange:(NSNotification *)notification {
...
}
Have a breakpoint in -handleTextChange:
, but doesn't get fired.
textField is connected in the Interface Builder.
Works on iOS6 iPhone/iPad simulator, on iOS5.1 iPad2, but not on iOS6 iPad3.
Irena is correct, UITextFieldTextDidChangeNotification does not fire when the text field is set programmatically. However I would just like to clarify that it has nothing to do with iOS6, it has to do with the iOS 6 SDK. If you compile with the iOS 5.1 SDK, the UITextFieldTextDidChangeNotification notification will fire whenever the text field is changed, programmatically or otherwise, even if run on an iOS 6 device.
so I figured it out. What changed in IOS6 SDK is that if you change the text of textfield programmatically, it doesn't send a notification. I have a custom keyboard on all of those views. when I tap on a key, it changes the text field text value by adding whatever I typed in. In ios 5 it would send a notification "textdidchange", but not in ios6.
My use case was somewhat special, I was creating HH:MM:SS duration UITextField with characters entered from the back, therefore trapping characters in - (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
and then returning return (NO);
to forbid auto-update of UITextField... pre-iOS6, it called the notification, post-iOS6, I'm simply calling [[NSNotificationCenter defaultCenter] postNotificationName:UITextFieldTextDidChangeNotification object:self.textField];
just before the return
statement.
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