gpt4 book ai didi

objective-c - 使用 RestKit 搜索 CoreData

转载 作者:行者123 更新时间:2023-11-28 22:51:40 25 4
gpt4 key购买 nike

我正在开发一个有两个模型的应用程序,在一个 View Controller 中,我想进行搜索并从两个模型中查找与搜索关键字匹配的实例,并将它们列在 TableView 中。我还使用 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 委托(delegate)方法如下所示:

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

任何有关此类搜索的外观的想法都很棒!

最佳答案

您可能想看看 RKGitHub示例项目,展示了 RKTableController 类的特性。

至于错误,我认为与你的问题无关。

关于objective-c - 使用 RestKit 搜索 CoreData,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11831166/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com