我可以用这个代码使用谓词过滤这个值
nspredicate *predicate = [nspredicate predicateWithFormat:@"self.firstname beginswith[cd]%@",searchString];self.filteredAllClIEnts = [AllClIEnts filteredArrayUsingPredicate:predicate];
我可以使用两个谓词过滤这个数组吗?
例如:我有名字(杰克·斯通,迈克·兰戈)
>如果我进入’J’,我应该得到过滤数组 – 杰克·斯通
>但是如果我进入’R’,我应该得到过滤的区域 – 麦克·兰戈?
nspredicate *firstnamePredicate = [nspredicate predicateWithFormat:@"self.firstname beginswith[cd]%@",searchString];nspredicate *lastnamePredicate = [nspredicate predicateWithFormat:@"self.lastname beginswith[cd]%@",searchString];nspredicate *compoundPredicate = [NSCompoundPredicate orPredicateWithSubpredicates:@[firstnamePredicate,lastnamePredicate]];self.filteredAllClIEnts = [AllClIEnts filteredArrayUsingPredicate:compoundPredciate];
然后,这将显示所有以名字从搜索开始的人,或者姓氏以搜索开始.
我更喜欢使用这种格式在单个谓词中使用OR和AND,因为它使整个代码更易读.
这也可以用来获得谓词的NOT.
如果您使用单个谓词内置复合谓词,也可以很容易地感到困惑.
总结以上是内存溢出为你收集整理的如何在IOS中使用两个谓词过滤UITableView全部内容,希望文章能够帮你解决如何在IOS中使用两个谓词过滤UITableView所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)