我使用以下代码过滤我的数组
NSArray *_filteredArray = [self.allData filteredArrayUsingPredicate:[NSPredicate predicateWithBlock:^BOOL(id evaluatedObject, NSDictionary *bindings) {
NSDictionary *_dataRow = (NSDictionary *)evaluatedObject;
return ([[[_dataRow valueForKey:@"name"] lowercaseString] rangeOfString:[self.searchBar.text lowercaseString]].location != NSNotFound);
}]];
正如您在代码段中看到的,我只匹配@"name"
;如何检查第二个参数(例如@"city"
)与我的过滤器匹配?
我尝试了allKeys
和allValues
,但都没有效果。
答案 0 :(得分:0)
做这样的事情:
NSArray *_filteredArray = [self.allData filteredArrayUsingPredicate:[NSPredicate predicateWithBlock:^BOOL(id evaluatedObject, NSDictionary *bindings) {
NSDictionary *_dataRow = (NSDictionary *)evaluatedObject;
return ([[[_dataRow valueForKey:@"name"] lowercaseString] rangeOfString:[self.searchBar.text lowercaseString]].location != NSNotFound) || ([[[_dataRow valueForKey:@"surname"] lowercaseString] rangeOfString:[self.searchBar.text lowercaseString]].location != NSNotFound);
}]];