0

私はこのような配列を持っています

NSMutableArray *level1;
NSMutableArray *level2;
NSMutableArray *level3;

self.questionSections=[[NSArray alloc] initWithObjects:@"Level 1",@"Level 2",@"Level 3", nil];

level1=[[NSMutableArray alloc] init];
level2=[[NSMutableArray alloc] init];
level3=[[NSMutableArray alloc] init];

[level1 addObject:[[NSDictionary alloc] initWithObjectsAndKeys:
                   @"What is the opposite of up?",@"name",
                   @"101q.png",@"questionpicture",
                   nil]];

[level1 addObject:[[NSDictionary alloc] initWithObjectsAndKeys:
                   @"What is the opposite of front?",@"name",
                   @"102q.png",@"questionpicture",
                   nil]];


[level2 addObject:[[NSDictionary alloc] initWithObjectsAndKeys:
                   @"Name a common pet?",@"name",
                   @"201q.png",@"questionpicture",
                   nil]];


[level2 addObject:[[NSDictionary alloc] initWithObjectsAndKeys:
                   @"Name a common bird?",@"name",
                   @"202q.png",@"questionpicture",
                   nil]];


[level3 addObject:[[NSDictionary alloc] initWithObjectsAndKeys:
                   @"List 3 rooms in your house?",@"name",
                   @"301q.png",@"questionpicture",
                   nil]];

self.questionData=[[NSArray alloc] initWithObjects:level1,level2,level3, nil];

で、検索したいです。私はこれを試していますが、どこにも行きません

NSPredicate *resultPredicate=[NSPredicate predicateWithFormat:@"name CONTAINS 'the'"];

NSLog(@"%@",resultPredicate);
NSLog(@"%@",self.questionData);

self.searchResults=[self.questionData  filteredArrayUsingPredicate:resultPredicate];

NSLog(@"%@",self.searchResults);

resultPredicate「name CONTAINS 'the'」は問題ないようです

self.questionData元気に見える

でもself.searchResultsただの ( )

役立つアイデアは素晴らしいでしょう。ありがとう。

4

2 に答える 2

5

これを解決するためにサブクエリを使用しました

 NSArray *questionData=[[NSArray alloc] initWithObjects:level1,level2,level3, nil];

 NSPredicate *resultPredicate=[NSPredicate predicateWithFormat:@"SUBQUERY(name, $content, $content CONTAINS %@).@count > 0", @"the"];

 NSArray *searchResults=[questionData  filteredArrayUsingPredicate:resultPredicate];

 NSLog(@"%@",searchResults);

結果::

(
    (
            {
        name = "What is the opposite of up?";
        questionpicture = "101q.png";
    },
            {
        name = "What is the opposite of front?";
        questionpicture = "102q.png";
    }
)

)

于 2013-07-18T12:47:35.910 に答える