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 に答える