UITextField 从大型数据库自动建议

发布于 2024-09-18 03:46:21 字数 324 浏览 11 评论 0原文

我正在尝试为 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

只是偏爱你 2024-09-25 03:46:21

您是否考虑过使用 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/

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文