私はあらゆる種類のマルチスレッドに慣れていないので、バックグラウンドスレッドで適切に機能する単純な検索方法を取得できないようです。メインスレッドで NSAutoreleasePool と UI が更新されているため、すべてが順調に進んでいるようです。アプリはクラッシュせず、バックグラウンドで検索を実行しますが、入力の速さによっては、検索結果に同じ項目が何度か表示されます。しかし、私が扱っている大量のデータのために非常に遅いです。コードは次のとおりです。
- (void)filterContentForSearchText:(NSString*)searchText {
isSearching = YES;
NSAutoreleasePool *apool = [[NSAutoreleasePool alloc] init];
/*
Update the filtered array based on the search text and scope.
*/
//[self.filteredListContent removeAllObjects]; // First clear the filtered array.
for (Entry *entry in appDelegate.entries)
{
NSComparisonResult result = [entry.gurmukhiEntry compare:searchText options:(NSCaseInsensitiveSearch|NSDiacriticInsensitiveSearch) range:NSMakeRange(0, [searchText length])];
if (result == NSOrderedSame)
{
[self.filteredListContent addObject:entry];
}
}
[self.searchDisplayController.searchResultsTableView performSelectorOnMainThread:(@selector(reloadData)) withObject:nil waitUntilDone:NO];
//[self.searchDisplayController.searchResultsTableView reloadData];
[apool drain];
isSearching = NO; }
- (BOOL)searchDisplayController:(UISearchDisplayController *)controller shouldReloadTableForSearchString:(NSString *)searchString {
if (!isSearching) {
[self.filteredListContent removeAllObjects]; // First clear the filtered array.
[self performSelectorInBackground:(@selector(filterContentForSearchText:)) withObject:searchString];
}
//[self filterContentForSearchText:searchString];
return NO; // Return YES to cause the search result table view to be reloaded. }