OGeek|极客世界-中国程序员成长平台

标题: ios - 如何使用谓词在 NSMutableArray 上搜索内容 [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-12 10:51
标题: ios - 如何使用谓词在 NSMutableArray 上搜索内容

我有一个 NSMutableArray 它有几个像这样的字典对象。

"DisplayName": "ART42 - Jomon Williams", 
    "DisplayName2": "Jomon Williams", 
    "EmployeeNumber": "ART42", 
    "Designation": "Senior Executive - Systems", 

我有一个 UITextField,当它的文本发生变化时,我想用搜索过滤数组重新加载我的 UITableView。对于搜索,我做了这样的事情。当我的文字发生变化时,我正在这样做。

    NSPredicate *exists = [NSPredicate predicateWithFormat"SELF CONTAINS[cd] %@", searchText];
    NSLog(@"redicate-------%@",exists);

    NSArray *aList = [mutArrayStaff filteredArrayUsingPredicate:exists];

我想通过 DisplayName2 键进行搜索。每次我的 aList 数组为空。如何正确编写谓词以便在 DisplayName2

上进行搜索

请帮助我。 谢谢



Best Answer-推荐答案


假设 mutArrayStaff 是一个字典列表,每个字典都包含 DisplayName2 作为键,您可以执行以下操作:

NSPredicate *exists = [NSPredicate predicateWithFormat"(DisplayName2 CONTAINS[cd] %@)", searchText];

关于ios - 如何使用谓词在 NSMutableArray 上搜索内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36378984/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://ogeek.cn/) Powered by Discuz! X3.4