问题
I am trying to add suggestions for a UITextField. They show up as a UITableView below the text field that displays a few entries according to what the user is typing (like Google Suggest for example).
The only method I tried so far is a select from an internal SQLite database. This works, but it is extremely slow as the database is really large (approx. 35000 entries). Everytime something is typed, the app freezes for 4 or 5 seconds before showing up new suggestions. So I guess this method ain't the best.
I was thinking of mapping everything in an NSDictionary but I'm afraid the table is too big (about 1.5MB) and keeping the NSDictionary permanently would be very costful in terms of memory.
What do you guys think would be best?
回答1:
have you thought of using NSThread to create the array that will be used by the table view? (don't do any UIKit calls through this though). If you run it all on the main thread, it'll be way slower, especially since your database is large.
If you don't know how NSThread works, check out this awesome tutorial: http://www.xprogress.com/post-36-threading-tutorial-using-nsthread-in-iphone-sdk-objective-c/
来源:https://stackoverflow.com/questions/3654475/uitextfield-auto-suggest-from-a-large-database