我试图搜索多个字段。例如:NSPredicate多字段搜索
[NSPredicate predicateWithFormat:@"(name title contains[cd] %@) AND (title contains[cd] %@", self.searchBar.text];
搜索名称字段或标题字段。
此外,如果有人知道通配符搜索会是什么样子,我也会很感激。
我想:
[NSPredicate predicateWithFormat:@"* contains[cd] %@", self.searchBar.text];
我的错误代码:
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Unable to parse the format string "(name contains[cd] %@) OR (title contains[cd] %@"'
我试过了这个语法,它和OR和AND都崩溃了。名称和标题是一个错字。感谢您的答复。 – hanumanDev 2011-05-31 22:27:51
对于每个说明符序列(例如'%@'),即使值相同,也必须提供一个值。所以你需要在你的格式字符串后面加上'self.searchBar.text'两次。此外,您需要关闭格式字符串中的第二个括号(即用')结束以平衡第二个(')。 – 2011-06-01 14:43:57