我使用过滤我的表格结果NSPredicate
NSPredicate *resultPredicate = [NSPredicate
predicateWithFormat:@"Name CONTAINS[cd] %@ OR Address CONTAINS[cd] %@",
searchText,
searchText];
searchResults = [NSMutableArray array];
for (key in dict) {
if ([resultArray containsObject:key]) {
NSArray *array = [dict objectForKey:key];
matches = [array filteredArrayUsingPredicate:resultPredicate];
if (matches.count > 0) {
[searchResults addObjectsFromArray:matches];
// sorting array
NSSortDescriptor *sort=[NSSortDescriptor sortDescriptorWithKey:@"Distance" ascending:YES];
[searchResults sortUsingDescriptors:[NSArray arrayWithObject:sort]];
}
}
}
}
然后我使用排序结果数组NSSortDescriptor
NSSortDescriptor *sort=[NSSortDescriptor sortDescriptorWithKey:@"Distance" ascending:YES];
[searchResults sortUsingDescriptors:[NSArray arrayWithObject:sort]];
它正在工作,但并非适用于所有结果: