UISearchBar协议常用方法

//点击键盘上的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 = @"";

[self resetSearch];

[table reloadData];

[searchBar resignFirstResponder];

}

//点击搜索框时调用

  • (void) searchBarTextDidBeginEditing:(UISearchBar *)searchBar

{

isSearching = YES;

[table reloadData];

}

你可能感兴趣的:(iOS技术之UI)