- (BOOL)searchDisplayController:(UISearchDisplayController *)controller shouldReloadTableForSearchString:(NSString *)searchString
{
[self.filteredList removeAllObjects]; // First clear the filtered array.
NSArray *objcts = unfilteredList;
for (NSDictionary *section in objcts)
{
for (NSDictionary *row in [section valueForKey:@"Rows"])
{
NSRange rng = [[row valueForKey:@"name"] rangeOfString:searchString options:(NSCaseInsensitiveSearch|NSDiacriticInsensitiveSearch)];
if (rng.length != 0)
[self.filteredList addObject:row];
}
}
// Return YES to cause the search result table view to be reloaded.
return YES;
}
确保您Search Bar and Search Display Controller
delegate
设置正确。然后用于显示单元格使用:
NSArray *rows;
if (tableView == self.searchDisplayController.searchResultsTableView)
{
rows = filteredList;
} else {
NSDictionary *section = [unfilteredList objectAtIndex:indexPath.section];
rows = [section objectForKey:@"Rows"];
}
cell.textLabel.text = [[rows objectAtIndex:indexPath.row] objectForKey:@"name"];
并更改 , 等的rowCount
逻辑titleHeader
。