#pragma mark - UISearchResultsUpdating
- (void)updateSearchResultsForSearchController:(UISearchController *)searchController
{
[searchResults removeAllObjects];
NSString *searchString = searchController.searchBar.text;
if([searchString length]>0){
for(NSUInteger i =0; i < titles.count; i++){
NSDictionary *titleAndIndex = [NSDictionary dictionaryWithObjectsAndKeys:[titles objectAtIndex:i], @"title",[ChNames objectAtIndex:i], @"ChName",[checkon objectAtIndex:i], @"checkon",[NSNumber numberWithUnsignedInteger:i], @"index",nil];
[searchResults addObject:titleAndIndex];
NSLog(@"filteredArray2: %@", titleAndIndex);
}
[searchResults filterUsingPredicate:[NSPredicate predicateWithFormat:@"title contains[c] %@",searchString]];
}
[self.tableView reloadData];
}
#pragma mark - UISearchBarDelegate
- (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar {
[searchBar resignFirstResponder];
}
答案 0 :(得分:0)
尝试下面的代码,它可以帮助你。
- (void)updateSearchResultsForSearchController:(UISearchController *)searchController {
[searchResults removeAllObjects];
self.tableView.allowsMultipleSelectionDuringEditing = YES;
NSString *searchString = searchController.searchBar.text;
for(NSUInteger i =0; i < titles.count; i++){
NSDictionary *titleAndIndex = [NSDictionary dictionaryWithObjectsAndKeys:
[titles objectAtIndex:i], @"title",nil];
[searchResults addObject:titleAndIndex];
// NSLog(@"filteredArray2: %@", titleAndIndex);
}
[searchResults filterUsingPredicate:[NSPredicate
predicateWithFormat:@"title contains[c] %@",searchString]];
dispatch_async(dispatch_get_main_queue(), ^{
[self.tableView reloadData];
});
}