0

我只需要在设置中设置为 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名字resultArray,它收集我在设置中设置为 ON 的数组

NSLog(@"%@", resultArray);

2013-05-01 11:40:46.917 testApp[5378:907] (
    Green,
    Orange,
    Blue
)

如何仅在 中搜索resultArray?我试过:

NSArray *array = [dict objectForKey:resultArray];

但没有成功。

这仅适用于一个数组:

NSArray *array = [dict objectForKey:@"Blue"];

我的数据结构是:

数据结构

4

1 回答 1

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

        }        

    }

}
于 2013-05-01T09:08:01.090 回答