NSPredicate过滤无结果

时间:2017-06-29 07:00:21

标签: ios objective-c arrays nspredicate

我正在尝试预测数组 有了这个      - (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”作为谓词

1 个答案:

答案 0 :(得分:2)

更新你的谓词:

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