我正在使用下面的代码为iPhone应用程序构建一个NSPredicate。测井结果显示:位置包含“头”,形状包含“椭圆形”,纹理包含“凹凸不平”,颜色包含“红色”。
我没有得到任何结果。如果我将谓词限制在单个项上,它将会起作用,超过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];发布于 2010-08-10 00:37:19
您的谓词要求可过滤对象中的所有值都是字符串。对吗?
另外,我会将子谓词的创建简化为:
NSPredicate * p = [NSPredicate predicateWithFormat:@"%K CONTAINS %@", [Title lowercaseString], [Value lowercaseString]];https://stackoverflow.com/questions/3442104
复制相似问题