我只需要在设置中设置为ON的数组中进行搜索和过滤。
现在我循环所有数组的dict
:
- (void)filterContentForSearchText:(NSString*)searchText scope:(NSString*)scope
{
NSPredicate *resultPredicate = [NSPredicate
predicateWithFormat:@"Name CONTAINS[cd] %@ OR Address CONTAINS[cd] %@",
searchText,
searchText];
searchResults = [NSMutableArray array];
for (NSString *akey in dict) {
NSLog(@"%@", akey);
NSArray *array = [dict objectForKey:akey];
NSArray *matches = [array filteredArrayUsingPredicate:resultPredicate];
if (matches.count > 0) {
[searchResults addObjectsFromArray:matches];
}
}
}
NSLog(@“%@”,akey);
2013-05-01 11:34:07.256 testApp[5357:907] White
2013-05-01 11:34:07.262 testApp[5357:907] Yellow
2013-05-01 11:34:07.274 testApp[5357:907] Greenyellow
2013-05-01 11:34:07.275 testApp[5357:907] Darkblue
2013-05-01 11:34:07.277 testApp[5357:907] Green
2013-05-01 11:34:07.283 testApp[5357:907] Purple
2013-05-01 11:34:07.284 testApp[5357:907] Blue
2013-05-01 11:34:07.289 testApp[5357:907] Black
2013-05-01 11:34:07.291 testApp[5357:907] Red
2013-05-01 11:34:07.294 testApp[5357:907] Orange
2013-05-01 11:34:07.299 testApp[5357:907] BlueYellow
2013-05-01 11:34:07.305 testApp[5357:907] Brown
2013-05-01 11:34:07.308 testApp[5357:907] Rose
2013-05-01 11:34:07.312 testApp[5357:907] Gray
我有一个名为NSMutableArray
的{{1}}收集我在设置中设置为ON的数组
NSLog(@“%@”,resultArray);
resultArray
如何仅在2013-05-01 11:40:46.917 testApp[5378:907] (
Green,
Orange,
Blue
)
中搜索?我试过了:
resultArray
但没有成功。
这只适用于一个数组:
NSArray *array = [dict objectForKey:resultArray];
我的数据结构是:
答案 0 :(得分:0)
尝试
- (void)filterContentForSearchText:(NSString*)searchText scope:(NSString*)scope
{
NSPredicate *resultPredicate = [NSPredicate
predicateWithFormat:@"Name CONTAINS[cd] %@ OR Address CONTAINS[cd] %@",
searchText,
searchText];
searchResults = [NSMutableArray array];
for (NSString *akey in dict) {
if ([resultsArray containsObject:aKey]) {
NSArray *array = dict[akey];
NSArray *matches = [array filteredArrayUsingPredicate:resultPredicate];
if (matches.count > 0) {
[searchResults addObjectsFromArray:matches];
}
}
}
}