UISearchBar继承自UIView,为iOS中具有搜索功能的控件。
UISearchBar的使用与UITextView的使用方法类似,
经过测试,可以得知UISearchBarDelegate
相关方法的调用情况
#pragma mark - UISearchBarDelegate
// return NO to not become first responder
- (BOOL)searchBarShouldBeginEditing:(UISearchBar *)searchBar{
NSLog(@">>搜索输入框将要开始编辑");
return YES;
}
// called when text starts editing
- (void)searchBarTextDidBeginEditing:(UISearchBar *)searchBar{
NSLog(@">>搜索输入框开始编辑");
}
// return NO to not resign first responder
- (BOOL)searchBarShouldEndEditing:(UISearchBar *)searchBar{
NSLog(@">>搜索输入框将要结束编辑");
return YES;
}
// called when text ends editing
- (void)searchBarTextDidEndEditing:(UISearchBar *)searchBar{
NSLog(@">>搜索输入框结束编辑");
}
// called when text changes (including clear)
- (void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText{
NSLog(@">>搜索输入框内的内容 %@",searchText);
self.filterString = searchText;
}
- (BOOL)searchBar:(UISearchBar *)searchBar shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text{
NSLog(@">>键盘新输入的内容 %@",text);
return YES;
}
- (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar{
[searchBar resignFirstResponder];
NSLog(@">>点击键盘搜索按钮");
}
- (void)searchBarBookmarkButtonClicked:(UISearchBar *)searchBar{
NSLog(@">>点击 BookmarkButton,需要设置属性showsBookmarkButton");
}
- (void)searchBarCancelButtonClicked:(UISearchBar *)searchBar{
NSLog(@">>点击 CancelButton,需要设置属性showsCancelButton");
}
- (void)searchBarResultsListButtonClicked:(UISearchBar *)searchBar{
NSLog(@">>点击 SearchResultsButton,需要设置属性showsSearchResultsButton");
}