I have a UITableView that has some cells and I add a UITextField to each of the cells.
I set textField.clearButtonMode = UITextFieldViewModeWhileEditing.
When I am editing the textField, the clear button and the keyboard both come out. I type some words in the textField, then tap the clear button, the keyboard will be hidden but the text in the textField will not be cleared.
All of the others work well except the clear button.
I had this problem because I had forgotten I was using a
UITapGestureRecognizerto catch taps on the table to dismiss the keyboard and it was capturing the tap on the clear button, preventing it from functioning. AddcancelsTouchesInView=NOon theUITapGestureRecognizerto let the touches still take effect and check usingCGRectContainsPointon the tapper method to only end editing andresignFirstResponderonly when the tap wasn’t on the currentUITextField‘s frame rect. Note that this still isn’t totally perfect since tapping X on an autocorrect might be outside the text field’s frame rect, so maybe checking the cell’scontentViewwould be better.