【发布时间】:2012-08-29 09:09:57
【问题描述】:
我想根据多个参数搜索我的 eventList 数组 像标题,结束日期等... 我正在使用以下代码 当我只使用一个参数标题时,如 [cd] %@ 它完美地工作
NSCharacterSet *whitespace = [NSCharacterSet whitespaceAndNewlineCharacterSet];
NSString *trimmed = [searchBar.text stringByTrimmingCharactersInSet:whitespace];
if([trimmed isEqualToString:@""]==NO)
{
// NSPredicate *predicate = [NSPredicate predicateWithFormat:@"title like[cd] %@",[NSString stringWithFormat:@"*%@*", searchBar.text]];
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"title like[cd] %@ || enddate like[cd] %@ ",[NSString stringWithFormat:@"*%@*", searchBar.text],[NSString stringWithFormat:@"*%@*", searchBar.text]];
NSLog(@"Main Array:%@",arrMain);
eventsList =(NSMutableArray*) [arrMain filteredArrayUsingPredicate:predicate];
[eventsList retain];
NSLog(@"Search Result:%@",eventsList);
[eventTable reloadData];
}
我试过了
NSPredicate predicate = [NSPredicate predicateWithFormat:@"(title like[cd] %@) OR (enddate like[cd] %@) ",[NSString stringWithFormat:@"%@", searchBar.text],[NSString stringWithFormat:@"%@*", searchBar.text]];
它也有效,但不准确,因为我正在搜索它不会显示的特定日期 但如果我写 2 或 p 或 a 它只适用于某些结果......所以我可以说它不完美 和 我的结束日期是格式为 2012-09-04 18:28:02 的字符串 任何人都可以帮我解决这个问题....
【问题讨论】:
-
我尝试过使用 NSPredicate predicate = [NSPredicate predicateWithFormat:@"(title like[cd] %@) OR (enddate like[cd] %@) ",[NSString stringWithFormat:@ "*%@", searchBar.text],[NSString stringWithFormat:@"%@", searchBar.text]];
标签: iphone search nspredicate