0
두 가지 모델이있는 뷰 컨트롤러에서 검색을 수행하고 검색 키워드와 일치하는 두 모델의 인스턴스를 찾고 테이블 뷰에 나열하려고합니다. 또한 RestKit을 사용하여 코어 데이터에 객체를 저장합니다. 나중에 로컬 검색을 수행 한 후 나중에 검색 결과를 서버 결과로 업데이트하려고합니다.RestKit을 사용한 CoreData 검색
나의 현재 - 아마 순진 - 시도는 다음과 같습니다
이것은 오류가 발생- (void)search
{
if (self.searchField.text !=nil) {
NSPredicate *predicate =[NSPredicate predicateWithFormat:@"post contains[cd] %@", self.searchField.text];
self.posts = [[Post findAllWithPredicate:predicate] mutableCopy];
// reload the table view
[self.tableView reloadData];
}
[self hideKeyboard];
}
:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *cellIdentifier = @"Cell";
CustomTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
if (cell == nil) {
cell = [[CustomTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
}
Post *post = [self.posts objectAtIndex:indexPath.row];
cell.titleLabel.text = post.title;
cell.selectionStyle = UITableViewCellSelectionStyleNone;
return cell;
}
:
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'unimplemented SQL generation for predicate : (post CONTAINS[cd] "t")'
가있는 tableView의 cellForRowAtIndexPath
위임 방법은 다음과 같습니다
이런 식으로 검색하는 방법에 대한 아이디어는 정말 좋을 것입니다!
문제는 주로 NSCompoundPredicate를 사용하여 내 술어로 해결되었습니다. 나는 또한 술어가 어떻게 작동하는지 오해했다. 어쨌든, 당신의 대답을 주셔서 감사합니다, 링크가 멋지다. – Anders