UITextField clear glitch - text highlights, selection carets appear

284 views Asked by At

I'm seeing a glitch in a UITextField when you tap on the clear button (the little X). Immediately before the text disappears, the selection carets appear (the vertical lines you move to select text) and then the text highlights as if it were selected. This only happens for an instant -- the highlight and carets flash on then immediately go away. The text does, in fact, clear -- the problem is that it's a distracting visual glitch.

Has anyone seen this?

Related question: Is there a notification posted or delegate method called somewhere when text is highlighted? I could use that to detect the flash. But, I can't seem to find anything...

1

There are 1 answers

1
capikaw On BEST ANSWER

I also experienced this issue, on iOS8. My class is observing UITextFieldTextDidChangeNotification. Although I didn't find the explanation of WHY it's happening I found the following UITextField delegate fixed it for me:

- (BOOL)textFieldShouldClear:(UITextField *)textField {
    textField.text = nil;
    return YES;
}

Just nil the textfield text on 'clear' - takes care of the visual glitch.