Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UITextFieldTextDidChangeNotification doesn't get called on ios6 ipad3

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.

like image 745
Irina Avatar asked Oct 05 '12 22:10

Irina


3 Answers

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.

like image 103
Mr. Cairo Avatar answered Nov 15 '22 19:11

Mr. Cairo


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.

like image 20
Irina Avatar answered Nov 15 '22 19:11

Irina


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.

like image 45
Miro Hudak Avatar answered Nov 15 '22 19:11

Miro Hudak