我有一個模型:的iOS簡單謂 '包含' 不工作
地方< --- >>類別
當執行下面的查詢:
NSFetchRequest *req = [NSFetchRequest fetchRequestWithEntityName:@"Category"];
if(![searchText isEqualToString:@""] && searchText != nil){
req.predicate = [NSPredicate predicateWithFormat:@"(places.placeTitle contains %@) OR (places.details contains %@) OR (name contains %@)", searchText, searchText, searchText];
NSLog(@"ModelHelper.getResults: Search text given, creating predicate: %@", req.predicate);
}
req.sortDescriptors = [NSArray arrayWithObject:[NSSortDescriptor sortDescriptorWithKey:@"name"
ascending:YES
selector:@selector(localizedCaseInsensitiveCompare:)]];
NSFetchedResultsController *controller = [[NSFetchedResultsController alloc]initWithFetchRequest:req
managedObjectContext:context
sectionNameKeyPath:nil
cacheName:nil];
NSError *error = nil;
[controller performFetch:&error];
我收到脗合,應不在那裏,例如:
searchText = "1234"
第一個結果是:
category[0].name = "Bars"
category[0].places[0].placeTitle = "Aaa"
category[0].places[0].details = "Aaa"
category[0].places[1].placeTitle = "123456"
category[0].places[1].details = "123456"
category[0].places[2].placeTitle = "test"
category[0].places[2].details = "test"
有沒有我做錯了我的謂詞?謝謝。
req.predicate = [NSPredicate predicateWithFormat:@「(places.placeTitle包含%@)或(地方CONTAINS%@)或(名稱CONTAINS%@)「,searchText,searchText,searchText]; – 2013-04-11 03:41:27