Reputation: 2941
I'm working on an app where I have two models, in a view controller I want to make a search and find instances from both models that matches the search keywords and list them in a tableview. I also use RestKit to store objects in core data. I later also want to update the search result with server results later after I first have made a local search.
My current - probably naive - attempt looks like this:
- (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];
}
This results in the error:
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'unimplemented SQL generation for predicate : (post CONTAINS[cd] "t")'
The tableView's cellForRowAtIndexPath
delegate method looks like this:
- (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;
}
Any ideas on how a search like this should look would be great!
Upvotes: 0
Views: 559
Reputation: 10633
You might want to look at RKGitHub example project, which shows off the features of RKTableController class.
As for the error, I don't think it is related to your question.
Upvotes: 2