UITextField 从大型数据库自动建议
我正在尝试为 UITextField 添加建议。它们显示为文本字段下方的 UITableView,根据用户输入的内容显示一些条目(例如 Google Suggest)。
到目前为止我尝试过的唯一方法是从内部 SQLite 数据库中进行选择。这可行,但速度非常慢,因为数据库非常大(大约 35000 个条目)。每次输入内容时,应用程序都会冻结 4 或 5 秒,然后再显示新的建议。所以我想这个方法不是最好的。
我正在考虑将所有内容映射到 NSDictionary 中,但我担心表太大(大约 1.5MB)并且永久保留 NSDictionary 在内存方面会非常昂贵。
你们认为最好的是什么?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您是否考虑过使用 NSThread 创建表视图将使用的数组? (不过不要通过这个进行任何 UIKit 调用)。如果你在主线程上运行它,它会慢得多,特别是因为你的数据库很大。
如果您不知道 NSThread 是如何工作的,请查看这个很棒的教程:http://www.xprogress.com/post-36-threading-tutorial-using-nsthread-in-iphone-sdk-objective-c/
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/