3

UITextFieldDelegate 有一个方法,当用户单击该小图标- (BOOL)textFieldShouldClear:(UITextField *)textField时会调用该方法。x

我找不到类似的东西UISearchBaror UISearchBarDelegate。是否有另一种方法来确定该按钮/图标是否已在内部单击UISearchBar

4

2 回答 2

3

您可以使用:

searchBar:textDidChange:

根据参考,当按下 X 清除字段时也会调用它。

于 2012-08-17T19:52:44.900 回答
1

这个怎么样(并注意讨论语句):

searchBar:textDidChange:
Tells the delegate that the user changed the search text.

- (void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText
Parameters
searchBar
The search bar that is being edited.
searchText
The current text in the search text field.
Discussion
This method is also invoked when text is cleared from the search text field.

Availability
Available in iOS 2.0 and later.
Declared In
UISearchBar.h
于 2012-08-17T19:55:57.740 回答