Это решение отлично работает для меня.
// NSDictionary Format
{
18=(
{
content="Great Avijit",
id=abc
}
),
13=(
{
content="Stack Overflow is cool",
id=abc
}
),
}
// Шаг 1
-(void)filterContentForSearchText:(NSString *)searchText
{
[self.filterResultArray removeAllObjects];
NSPredicate *namePredicate = [NSPredicate predicateWithFormat:@"(content contains[cd] %@)", searchText];//from_user.name
//other
for (NSMutableDictionary *key in self.messageAll) {
NSArray *array=[self.messageAll objectForKey:key];
array=[array filteredArrayUsingPredicate:namePredicate];
if ([array count]==0) {
[self.filterResultArray removeObject:key];
}
else{
if ([self.filterResultArray containsObject:key]) {
}
else{
[self.filterResultArray addObject:key];
}
}
}
//Reload table view
[self.tableView reloadData];
}
// Шаг 2: numberOfRowsInSection
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
if (self.searchController.active && ![self.searchController.searchBar.text isEqualToString:@""]) {
return [self.filterResultArray count];
}else{
return [keyArray count];//keyArray hold all key of original dict
}
}
// Шаг 3: в методе cellForRowAtIndexPath
NSString *key = [self.filterResultArray objectAtIndex:indexPath.row];
NSDictionary *dictionary = [[self.messageAll objectForKey:key] lastObject];//self.messageAll is original dict