Ios 非预测滤波
我有以下json对象存储为Ios 非预测滤波,ios,objective-c,nspredicate,Ios,Objective C,Nspredicate,我有以下json对象存储为self.pElements。我有一个搜索栏,用于根据名称筛选项目 [ {"id":"1","name":"Baked Chicken","category":"1","price":"5.49"}, {"id":"2","name":"Beef Kabob","category":"2","price":"5.49"}, {"id":"3","name":"Beef Gyro","category":"1","price":"5.49"}, {"id":"4"
self.pElements
。我有一个搜索栏
,用于根据名称
筛选项目
[
{"id":"1","name":"Baked Chicken","category":"1","price":"5.49"},
{"id":"2","name":"Beef Kabob","category":"2","price":"5.49"},
{"id":"3","name":"Beef Gyro","category":"1","price":"5.49"},
{"id":"4","name":"Lamb Gyro","category":"4","price":"5.49"}
]
我尝试按name
进行如下筛选,但它总是返回null。即使我只输入了牛肉
,也没有返回任何内容
pTempElements =[[NSMutableArray alloc] initWithArray:[self.pElements filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:@"name = %@", self.searchBar.text]]];
如果要筛选包含搜索字符串的字符串,请使用
contains[cd]
:
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"name contains[cd] %@", searchText];
有关可以进行的字符串比较种类的列表,请参见谓词编程指南中的。没有一个“name”值等于“Beef”。
name=
=>它表示“完美匹配”。您可能需要将其替换为name begins with[c]
(c]用于case instive,以便“beef”可以。您能举个小例子吗?如果用户仅键入Gyro
怎么办?@hosting是否只显示包含Gyro的名称?