Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/95.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 非预测滤波_Ios_Objective C_Nspredicate - Fatal编程技术网

Ios 非预测滤波

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"

我有以下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","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的名称?