我UISearchbar
用取消按钮创建了一个,但是当我单击取消按钮时,它不显示数组,它只是关闭键盘。
allItems
是NSArray
和
displayItems
是NSMutableArray
-(void)searchBarSearchButtonClicked:(UISearchBar *)asearchBar{
[displayItems addObject:allItems];
[searchBar resignFirstResponder];
}
-(void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText{
if ([searchText length] == 0) {
[displayItems removeAllObjects];
[displayItems addObjectsFromArray:allItems];
} else {
[displayItems removeAllObjects];
for (NSString * string in allItems ){
NSRange r =[string rangeOfString:searchText options:NSCaseInsensitiveSearch];
if (r.location != NSNotFound){
[displayItems addObject:string];
}
}
[tableView reloadData];
}
}
- (UITableViewCellAccessoryType)tableView:(UITableView *)tableView accessoryTypeForRowWithIndexPath:(NSIndexPath *)indexPath{
return UITableViewCellAccessoryDisclosureIndicator;
}
-(void)searchBarCancelButtonClicked:(UISearchBar *)asearchBar{
[displayItems removeAllObjects];
[displayItems addObjectsFromArray:allItems];
[searchBar resignFirstResponder];
}
-(void)searchBarSearchButtonClicked:(UISearchBar *)asearchBar{
[searchBar resignFirstResponder];
}