ユーザーが画面上の他の場所をタップしたときにキーボードを閉じていたときに、この問題が発生しました。タップを探すジェスチャレコグナイザーがあり、タップが検出されると、テキストフィールドでresignFirstResponderが呼び出されます。残念ながら、それはクリアボタンを壊します。
私がしたことは、タップをフィルタリングしてテーブルビューの外側にあることを確認することでした。ボタンのタップを手動でトリガーする必要があるため、少し複雑になりました。
// In: - (void)handleTap:(UITapGestureRecognizer *)sender {
// The user tapped outside a text field, drop the keyboard.
// Unfortunately this normally breaks the clear button, so we'll check that the
// tap is outside the table view (and therefore not on a clear button).
BOOL inButton = CGRectContainsPoint(self.signInButton.bounds, [sender locationInView:self.signInButton]);
BOOL inTable = CGRectContainsPoint(self.tableView.bounds, [sender locationInView:self.tableView]);
if (!inTable && !inButton ) {
BOOL didEndEditing = [self.view endEditing:NO];
// But... if we were editing a field (& therefore the keyboard is showing),
// and if they tapped the sign in button, sign in. Not sure where the
// onSignIn event is getting lost. The button does highlight. But the
// call to endEditing seems to eat it.
if (didEndEditing && inButton) {
[self onSignIn:self.signInButton];
}
}