iPhone 앱의 경우 아래 코드를 사용하여 NSPredicate를 만듭니다. 로깅은 prediate가 다음을 보여줍니다 : location "head"AND shape 포함 "oval"AND texture "bumpy"AND color "CONVINS"빨간색 "NSCompoundPredicate가 일치하지 않습니다.
결과가 없습니다. 술어를 단일 항목으로 제한하면 1보다 많은 수가 실패합니다.
아무도 말해 줄 수 있습니까?
많은 감사
NSMutableArray *subPredicates = [[NSMutableArray alloc] init];
for (Ditem in self.tableDataSource) {
NSString *Title = [Ditem valueForKey:@"Title"];
NSString *Value = [Ditem valueForKey:@"Value"];
if([[Value lowercaseString] isEqualToString: @"all"]){
Value = @"";
}
else{
NSPredicate *p = [NSComparisonPredicate predicateWithLeftExpression:[NSExpression expressionForKeyPath:[Title lowercaseString]] rightExpression:[NSExpression expressionForConstantValue:[Value lowercaseString]] modifier:NSDirectPredicateModifier type:NSContainsPredicateOperatorType options:0];
[subPredicates addObject:p];
}
}
NSPredicate *predicate = [NSCompoundPredicate andPredicateWithSubpredicates:subPredicates];
NSLog(@"predicate: %@", predicate);[self.fetchedResultsController.fetchRequest setPredicate:predicate];
좀 더 많은 정보를 추가하려면에
또한, 나는 당신의 subpredicate의 생성을 단순화합니다. 내가 한 일은 SELECT * FROM TABLE WHERE (위치 '% 머리 %')와 (모양 LIKE '% oval %') AND (텍스처 LIKE '% 울퉁불퉁 %') AND (색상 LIKE ' 빨간색 % ') – BigBadOwl