0

私は2つのモデルを持つアプリに取り組んでいます。ビューコントローラーで検索を行い、検索キーワードに一致する両方のモデルからインスタンスを見つけてテーブルビューにリストしたいと考えています。また、RestKit を使用してオブジェクトをコア データに格納します。また、最初にローカル検索を行った後、サーバーの結果で検索結果を更新したいと考えています。

私の現在の(おそらく素朴な)試みは次のようになります。

- (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];

}

これにより、次のエラーが発生します。

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'unimplemented SQL generation for predicate : (post CONTAINS[cd] "t")'

tableView のcellForRowAtIndexPathデリゲート メソッドは次のようになります。

- (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;
}

このような検索がどのように見えるべきかについてのアイデアは素晴らしいでしょう!

4

1 に答える 1

2

RKTableController クラスの機能を示すRKGitHubサンプル プロジェクトを参照してください。

エラーについては、ご質問とは関係ないと思います。

于 2012-08-06T15:59:56.453 に答える