1

我正在开发应用程序,我想显示一个 10k+ 的 tableview 我正在使用来自 cs193p 的 fetchedresultcontroller,它运行良好。加载和滚动非常快。我希望能够搜索每个字母。
我设置了搜索栏和委托,并让 searchbar textdidchange 方法为每个字母重新加载 fetchresults 控制器。它可以工作,但无论如何都会有延迟以使其更快。这是我的 textdidchange 方法

-(void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText {

//NSLog(@"%@",searchText);
NSFetchRequest *request = [NSFetchRequest fetchRequestWithEntityName:@"People"];
request.sortDescriptors = [NSArray arrayWithObject:[NSSortDescriptor sortDescriptorWithKey:@"fullname" ascending:YES]];
[NSFetchedResultsController deleteCacheWithName:@"peopleCache"];
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"(firstname contains[c] %@)",searchText];
 request.predicate = predicate;

self.fetchedResultsController = [[NSFetchedResultsController alloc]initWithFetchRequest:request managedObjectContext:self.peopleDatabase.managedObjectContext sectionNameKeyPath:nil cacheName:@"actorCache"];  

}

有什么方法可以过滤现有查询而不实际重新获取数据?

任何建议将不胜感激!

4

2 回答 2

1

“优化 iPhone OS 上的核心数据性能”WWDC 会议中提到了优化文本搜索的技巧。

于 2012-04-24T21:44:38.217 回答
0

您可以使用谓词搜索现有数组,但它可能会在您正在搜索的所有字段中出现错误......这取决于应用程序可能是一件坏事(即重新获取更慢且使用更多内存) .

于 2012-04-24T21:55:16.227 回答