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);
}]];

正如您在片段中看到的,我只匹配@"name";如何检查@"city"要与我的过滤器匹配的第二个参数(例如)?

我试过allKeysand allValues,但都没有奏效。

4

1 回答 1

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);
}]];
于 2013-11-12T14:36:16.103 回答