在我的项目中,我在 NSPredicate 工作,我已经为单个 NSPredicate 工作,但现在我需要使用多个 NSPredicate。这里我有一个数组,我想从这个数组中过滤多个案例,
我有三个这样的复选框,最初当我取消选择绿色按钮时全部选中意味着它只显示红色和黄色值然后我取消选择黄色意味着它再次只显示红色值我选择绿色意味着它显示绿色和红色值
IE
1.Color is equal or not equal to Green.
2.Color is equal or not equal to Yellow.
3.Color is equal or not equal to Red.
我的阵列组合了这三种颜色在这里我试过了,
NSPredicate *filterRun,*filterNotProd,*filterStop,*filterR;
if(isRun){
filterRun = [NSPredicate predicateWithFormat:@"Color != [c] %@",GREEN_COLOR];
}
else{
filterRun = [NSPredicate predicateWithFormat:@"Color == [c] %@",GREEN_COLOR];
}
if(isNotProd){
filterNotProd = [NSPredicate predicateWithFormat:@"Color != [c] %@",YELLOW_COLOR];
}
else{
filterNotProd = [NSPredicate predicateWithFormat:@"Color == [c] %@",YELLOW_COLOR];
}
if(isStop){
filterStop = [NSPredicate predicateWithFormat:@"Color != [c] %@",RED_COLOR];
}
else{
filterStop = [NSPredicate predicateWithFormat:@"Color == [c] %@",RED_COLOR];
}
// filterR = [NSPredicate predicateWithFormat:@"Color LIKE[c] %@",RED_COLOR];
NSLog(@"prediStr Runn %@ nnn %@ sss %@",filterRun,filterNotProd,filterStop);
NSPredicate *compFilter=[NSCompoundPredicate andPredicateWithSubpredicates:@[filterRun,filterNotProd,filterStop]];
// NSPredicate *compFilter=[NSCompoundPredicate orPredicateWithSubpredicates:@[filterRun,filterNotProd,filterStop]];
NSMutableArray *filteredArr = [NSMutableArray arrayWithArray:[parkDetailsArr filteredArrayUsingPredicate:compFilter]];
parkDetailsArr=[NSMutableArray arrayWithArray:filteredArr];
但它只显示空值..帮助我..