나는 3000 개가 넘는 항목이있는 표가 있으며 검색 속도가 매우 느립니다.UISearchbar를 사용하여 검색하면 느려지고 기본 스레드를 차단합니다.
는- (void) filterContentForSearchText:(NSString*)searchText
{
// Update the filtered array based on the search text
// First clear the filtered array.
[filteredListContent removeAllObjects];
// Search the main list whose name matches searchText
// add items that match to the filtered array.
if (fetchedResultsController.fetchedObjects)
{
for (id object in fetchedResultsController.fetchedObjects)
{
NSString* searchTarget = [tableTypeDelegate getStringForSearchFilteringFromObject:object];
if ([searchTarget rangeOfString:searchText
options:(NSCaseInsensitiveSearch|NSDiacriticInsensitiveSearch)].location != NSNotFound)
{
[filteredListContent addObject:object];
}
}
}
}
내 질문은 두 가지이다 : 다음과 같이 그냥
- (BOOL)searchDisplayController:(UISearchDisplayController *)controller shouldReloadTableForSearchString:(NSString *)searchString
{
[self filterContentForSearchText: searchString];
// Return YES to cause the search result table view to be reloaded.
return YES;
}
그리고 filterContentForSearchText의 방법 'TableSearch'예제 코드에서 (그러나 범위없이) 같은 일을하고있는 순간
입니다 :
- 어떻게 검색 프로세스를 빠르게 수행 할 수 있습니까?
- 어떻게 검색을 중단하여 메인 스레드를 차단할 수 있습니까? 즉 사용자가 더 많은 문자를 입력하는 것을 막습니다.
두 번째 부분에서는 "performSelector : withObject : afterDelay :"및 "cancelPreviousPerformRequests ..."를 많이 시도하지 않았습니다. 대신 스레딩을 사용해야 할 것으로 생각되지만, 많은 경험이 없습니다.
예, 좋습니다. – Robert