UITextFieldTextDidChangeNotification doesn't get called on ios6 ipad3

后端 未结 5 1522
天命终不由人
天命终不由人 2021-02-14 09:29

have the following:

// watch the fields
[[NSNotificationCenter defaultCenter]  addObserver:self
                                          selector:@selec         


        
相关标签:
5条回答
  • 2021-02-14 09:38

    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.

    0 讨论(0)
  • 2021-02-14 09:45

    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.

    0 讨论(0)
  • 2021-02-14 09:46

    As a temporary workaround until Apple fixes this, you can use the following code example:

    //view is a UITextField
    NSString *temp = ((UITextField*)view).text;
    ((UITextField*)view).text = @"";
    [((UITextField*)view) insertText:[NSString stringWithFormat:@"%@%@", @"-", temp]];
    

    That code will continue to fire the event.

    This works too:

    [((UITextField*)view) sendActionsForControlEvents:UIControlEventEditingChanged];
    
    0 讨论(0)
  • 2021-02-14 09:49

    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.

    0 讨论(0)
  • 2021-02-14 10:02

    On my ipad3 & iOS6.0 notification UITextFieldTextDidChangeNotification work fine. put

    [[NSNotificationCenter defaultCenter]  addObserver:self
                                          selector:@selector(handleTextChange:)
                                              name:UITextFieldTextDidChangeNotification
                                            object:textField1];
    

    in your viewDidLoad

    0 讨论(0)
提交回复
热议问题