【问题标题】:How to search something on NSMutableArray using predicate如何使用谓词在 NSMutableArray 上搜索某些内容
【发布时间】:2016-04-02 21:34:33
【问题描述】:

我有一个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(@"Predicate-------%@",exists);

    NSArray *aList = [mutArrayStaff filteredArrayUsingPredicate:exists];

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

请帮助我。 谢谢

【问题讨论】:

  • 你找到解决方案了吗?

标签: ios objective-c uitableview nsmutablearray nspredicate


【解决方案1】:

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-11-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-10-11
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多