UISearchBarDelegate和textFieldShouldClear替代

时间:2012-08-17 19:25:42

标签: ios uisearchbar

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

我找不到UISearchBarUISearchBarDelegate类似的内容。有没有其他方法可以找出是否在UISearchBar内点击了该按钮/图标?

2 个答案:

答案 0 :(得分:3)

您可以使用:

searchBar:textDidChange:

,当按下X以清除该字段时,也会调用Reference

答案 1 :(得分: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