NSPredicate 过滤得到没有结果

Posted

技术标签:

【中文标题】NSPredicate 过滤得到没有结果【英文标题】:NSPredicate to filter Getting No Results 【发布时间】:2017-06-29 07:00:20 【问题描述】:

我正在尝试对数组进行谓词 有了这个 -(void)searchBar:(UISearchBar*)searchBar textDidChange:(NSString*)text

if(text.length == 0)

    isFiltered = FALSE;

else

    isFiltered = true;
    filteredListCustomersArray = [[NSMutableArray alloc]initWithCapacity:[customersArray count]];

    [filteredListCustomersArray removeAllObjects];
    NSPredicate *filterPredicate = [NSPredicate predicateWithFormat:@"SELF.text contains[c] %@",text];
    filteredListCustomersArray = [NSMutableArray arrayWithArray:[customersArray filteredArrayUsingPredicate:filterPredicate]];
    searchText=text;

[customerstableView reloadData];

我无法得到结果。 请帮助我,

<__NSArrayM 0x608000458480>(

    FLD =     (
                
            NAME = BPCNUM;
            TYPE = Char;
            text = ACTR001;
        ,
                
            NAME = BPCNAM;
            TYPE = Char;
            text = "Regal Enterprises";
        ,
                
            NAME = BPCSHO;
            TYPE = Char;
            text = Regal;
        
    );
    NUM = 1;
,

    FLD =     (
                
            NAME = BPCNUM;
            TYPE = Char;
            text = ACTR003;
        ,
                
            NAME = BPCNAM;
            TYPE = Char;
            text = "Mace Supplies";
        ,
                
            NAME = BPCSHO;
            TYPE = Char;
            text = Mace;
        
    );
    NUM = 2;
)

这里我想要 text = "Regal Enterprises" 作为谓词

【问题讨论】:

什么是崩溃日志 编辑您的问题并添加崩溃日志 试试[NSPredicate predicateWithFormat:@"text contains[c] %@",text]; 需要显示崩溃日志 检查数组后,没有得到结果 NIRAV 如果你想要解决方案,你需要显示崩溃日志而不是数组 如果发生崩溃,请显示崩溃日志。此外,避免显示代码/数据的图像,而是复制/粘贴数组的条目。 【参考方案1】:

更新你的谓词:

NSPredicate *filterPredicate = [NSPredicate predicateWithFormat:@" ANY FLD.text contains[c] %@", text];
filteredListCustomersArray = [[customersArray filteredArrayUsingPredicate:filterPredicate] copy];

【讨论】:

谢谢兄弟,它运作良好。你节省了我的时间 Lal Krishna 在这里我只需要谓词索引 1 文本(“Regal Enterprises”、“Mace Supplies”)我该怎么做 使用 for-in 并通过 FLD[1] 获取价值 表示由 FLD[1] 文本断言? 没有。 for(FLDModel *FLD in arrayName) [customArray addObject: FLD[1]]; 类似的东西

以上是关于NSPredicate 过滤得到没有结果的主要内容,如果未能解决你的问题,请参考以下文章

简单的 NSPredicate @"1 == 0" 不过滤获取的结果?

NSPredicate:与日期iOS的to-Many关系

NSPredicate 使用 OR 错误

过滤掉子类结果的 NSPredicate

Core Data NSPredicate 过滤结果

NSPredicate 使用 CloudKit 进行不区分大小写的字符串搜索