How to increase search speed in the iPhone SDK

My iphone application displays a table view with a list of 6,000 items. (these items are in the SQLite file)

The user can search on these items. BUT, when I click on the search bar and start typing the first letter, I need age before I can enter the second letter. Likewise, it takes a long time to type each letter before I can start the search.

Is there a way to increase the input speed on the search toolbar so that the user can quickly enter 5-6 letters for the search?

I appreciate your help. Thank!

+3
source share
3 answers

, , , , . , Grand Central Dispatch (4.0+), NSOperation, performSelectorInBackground:.... / , .

: performSelectorInBackground:withObject: performSelectorOnMainThread:withObject:waitUntilDone:. - :

 // -searchForString: is our search method and searchTerm is the string we are searching for
 [self performSelectorInBackground:@selector(searchForString:) withObject:searchTerm];

Cocoa -searchForString: . , . :

- (void)searchForString:(NSString *)searchTerm
{
    // First create an autorelease pool (we must do this because we are on a new thread)
    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];

    // Perform the search as you normally would
    // The result should be an array containing your search results
    NSArray *searchResults = ...

    // Pass the search results over to the main thread
    [self performSelectorOnMainThread:@selector(searchDidFinishWithResult:) withObject:searchResults waitUntilDone:YES];

    // Drain the ARP
    [pool drain];
}

searchDidFinishWithResult: :

- (void)searchDidFinishWithResult:(NSArray *)searchResult
{
    // Update the UI with the search results
    ...
}

, , . , , , , . , , , (NSOperation ).

+6

, "textDidChange", , "searchBarSearchButtonClicked"?

, -, , .

+1

I do not know if your table is indexed. If not, you should create an index for your table. Updating the table will be slower, but the search should be faster. Good luck.

0
source

Source: https://habr.com/ru/post/1775259/


All Articles