开发者社区 问答 正文

关于使用NSPredicate过滤NSArray 的问题

有一个NSArray,我想用predicate过滤一下。

NSLog(@"text is %@",txtSearch.text);
NSPredicate *bPredicate =
[NSPredicate predicateWithFormat:@"SELF beginswith[c] '%@'",txtSearch.text];
arrSearchedPlayers =
[arrPlayers filteredArrayUsingPredicate:bPredicate];
NSLog(@"array after searched is %@",arrSearchedPlayers);

但是再输入文本时数组还是空的,使用下面的predicate的话就结果正常:

 NSPredicate *bPredicate =
    [NSPredicate predicateWithFormat:@"SELF beginswith[c] 's'"];

这是为什么呢?

展开
收起
爵霸 2016-03-24 10:59:02 1899 分享 版权
1 条回答
写回答
取消 提交回答
  • `
    NSPredicate *bPredicate =[NSPredicate predicateWithFormat:@"SELF beginswith[cd] %@",txtSearch.text];
    `

    2019-07-17 19:12:17
    赞同 展开评论
问答地址: