iOS开发学习笔记5:搜索栏
#pragma mark -
#pragma mark search bar delegate methods
//点击键盘上的search按钮时调用
- (void) searchBarSearchButtonClicked:(UISearchBar *)searchBar
{
NSString *searchTerm = searchBar.text;
[self handleSearchForTerm:searchTerm];
}
//输入文本实时更新时调用
- (void) searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText
{
if (searchText.length == 0) {
[self resetSearch];
[table reloadData];
return;
}
[self handleSearchForTerm:searchText];
}
//cancel按钮点击时调用
- (void) searchBarCancelButtonClicked:(UISearchBar *)searchBar
{
isSearching = NO;
search.text = @"";
[selfresetSearch];
[tablereloadData];
[searchBar resignFirstResponder];
}
//点击搜索框时调用
- (void) searchBarTextDidBeginEditing:(UISearchBar *)searchBar
{
isSearching = YES;
[tablereloadData];
}