1

很抱歉问这个问题,但我对此很陌生。嗨,我有一个NSMutableArray包含如下数据的数据:

{
Code = MCP3441G;
"Needle Description" = "1/2 Circle Round Body MH";
"Needle Dimension" = "31 MM";
"No. of foils per box" = 12;
"Per box maximum retail price" = 7440;
"Per box price to retailers & hospitals" = 5474;
Size = "2/0";
"Suture type and length" = "MONOCRYL monofilament 70 CM Violet";
nid = 86;
},
{
Code = NW1641;
"Needle Description" = "1/2 Circle Round Body";
"Needle Dimension" = "30 MM";
"No. of foils per box" = 12;
"Per box maximum retail price" = 4800;
"Per box price to retailers & hospitals" = 3510;
Size = "2/0 Only";
"Suture type and length" = "MONOCRYL Undyed Monofilament 70 CM";
nid = 86;
},
{
Code = NW1642;
"Needle Description" = "1/2 Circle Round Body";
"Needle Dimension" = "30 MM";
"No. of foils per box" = 12;
"Per box maximum retail price" = 4800;
"Per box price to retailers & hospitals" = 3510;
Size = "1/0";
"Suture type and length" = "MONOCRYL Undyed Monofilament 70 CM";
nid = 86;
},
{
Code = NW1648;
"Needle Description" = "3/8 Circle Round Body";
"Needle Dimension" = "16 MM";
"No. of foils per box" = 12;
"Per box maximum retail price" = 3600;
"Per box price to retailers & hospitals" = 2687;
Size = "4/0";
"Suture type and length" = "MONOCRYL Undyed Monofilament 70 cm";
nid = 86;
},

现在我想根据搜索过滤对象。例如,如果我输入NW1648所以最后一个对象应该只可见。意味着我部分:

{
Code = NW1648;
"Needle Description" = "3/8 Circle Round Body";
"Needle Dimension" = "16 MM";
"No. of foils per box" = 12;
"Per box maximum retail price" = 3600;
"Per box price to retailers & hospitals" = 2687;
Size = "4/0";
"Suture type and length" = "MONOCRYL Undyed Monofilament 70 cm";
nid = 86;
},

以下是我用来过滤数据的方法:

#pragma Search Method
-(void)filterContentForSearchText:(NSString *)searchText scope:(NSString*)scope{
    NSPredicate *predicate = [NSPredicate predicateWithFormat:@"SELF beginswith[c] %@",searchText];
    searchedData = [self->datas filteredArrayUsingPredicate:predicate];
}

-(BOOL)searchDisplayController:(UISearchDisplayController *)controller shouldReloadTableForSearchString:(NSString *)searchString{
    [self filterContentForSearchText:searchString scope:[[self.searchDisplayController.searchBar scopeButtonTitles] objectAtIndex:[self.searchDisplayController.searchBar selectedScopeButtonIndex]] ];
    return YES;
}

请帮助我。提前致谢。

更新#1:

I am storing below data in `NSMutableDictionary` like below:



  {
Code = NW1648;
"Needle Description" = "3/8 Circle Round Body";
"Needle Dimension" = "16 MM";
"No. of foils per box" = 12;
"Per box maximum retail price" = 3600;
"Per box price to retailers & hospitals" = 2687;
Size = "4/0";
"Suture type and length" = "MONOCRYL Undyed Monofilament 70 cm";
nid = 86;
},

 NSMutableDictionary *resultantDataObject = [[NSMutableDictionary alloc]init];
    [resultantDataObject setObject:[val valueForKey:CODE_ID] forKey:SKU_CODE];
    [resultantDataObject setObject:[val valueForKey:CODE_NEEDLE_DESC] forKey:NEEDLE_DESCRIPTION];
    [resultantDataObject setObject:[val valueForKey:CODE_NEEDLE_DIMENSION] forKey:NEEDLE_DIMENSION];
    [resultantDataObject setObject:[val valueForKey:CODE_SUTURE] forKey:SUTURE_TYPE];
    [resultantDataObject setObject:[val valueForKey:CODE_SIZE] forKey:SIZE];
    [resultantDataObject setObject:[val valueForKey:CODE_FOILS] forKey:FOILS_PER_BOXEX];
    [resultantDataObject setObject:[val valueForKey:CODE_RETAILS_HOSPITAL] forKey:HOSPITAL_PRICE];
    [resultantDataObject setObject:[val valueForKey:CODE_MAX_RETAIL] forKey:MAXIMUM_RETAILS];

我在这里添加NSMutableDictionary这个NSMutableArray

[data addObject:resultantDataObject];

更新#2:我现在有对象我想根据他输入的内容进行搜索,如果他34 Mono输入,所以我想在所有键中搜索这个,34 可以在任何键中,然后再次在所有键中搜索单声道并过滤具有两个关键字的值。

4

1 回答 1

0

尝试这个:

NSArray *filteredArr = [data filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:@"(Code == %@)", searchText]];
NSLog(@"%@",filteredArr);

希望这可以帮助.. :)

如果要添加更多密钥,请执行以下操作:

NSArray *filteredArr = [data filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:@"(Code == %@) AND (Needle Description == %@) AND (Needle Dimension == %@)", searchText,needleDescription, needleDimentsion]];
于 2015-01-19T05:00:28.783 回答