简体   繁体   中英

UITextFieldTextDidEndEditingNotification not working properly in TableVIew

I have a tableView in which I use an instance of a custom TableViewCell. In each custom cell, there's a textfield and a label.

Each time the text on the textField changes, I need to do some update in another textField present on the main UIView of my screen.

There are 6 rows in all

ISSUE : The UITextFieldTextDidEndEditingNotification is triggered only on the 1st, 4th and 6th row on a first attempt. Then on a 2nd attempt it would work only on the 1st and 4th. When I DEBUG, it WORKS sometimes, but then it again does NOT work.

=> It's like it is working randomly.

I cannot figure out what's going on, anyone can help or provide some hint to track down the cause?

The accepted answer solves the problem, but doesn't answer the question.

The reason why the UITextFieldTextDidEndEditingNotification wasn't working was because this notification only fires when the user finishes editing the field and closes the keyboard or selects another textfield.

What you should have been observing is the UITextFieldTextDidChangeNotification , which fires every time the text changes.

And you should prefer using the following callback method instead of UITextFieldTextDidEndEditing

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

    return YES;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM