I've had this problem that I have been putting off solving, but now is the time.
I have a basic dictionary program. It has a UISearchBar and a UITableView. It works the way that it should except when running on the device it causes Keyboard lag. (Simulator is fine, of course) I have two types of searching. As-you-type and On-return. I find that both take about the same amount of time to return results, but the As-you-type makes the keyboard lag.
I have UISearchBar textDidChange that takes the searchText and sends it to a search method that does all the sqlite lifting, puts the results in an Array. The reloads the table.
- (void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText{
if((searchType == SEARCH_AS_YOU_TYPE) && ([searchText length] >= 2)){
NSString *myKeyword = [NSString stringWithFormat:@"%@", searchText];
[self search:myKeyword];
[myTableView reloadData];
}
}
I limit the results to 50. And I my SQL query uses the LIKE and OR, no way around that yet.
SELECT WORD_ID, DEFIN, PINYIN, SIMP, TRAD from WORDS where DEFIN LIKE "%to dog %" OR DEFIN LIKE "%dog" OR DEFIN LIKE "%dog%" ORDER BY DEFIN LIMIT 50
I've also tried moving the [myTableView reloadData] into the search method, in hopes that the keyboard would at least not lag. No Joy. And sadly I know that sqlite is basically checking every row, when it uses the like operator. But 3-4 seconds for 80rows seems kinda slow.
Any thoughts, ideas, comments or suggestions would be greatly appreciated!