UITextField从大型数据库自动建议 [英] UITextField auto-suggest from a large database

查看:159
本文介绍了UITextField从大型数据库自动建议的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试为UITextField添加建议。它们显示为文本字段下方的UITableView,根据用户输入的内容显示一些条目(例如Google Suggest)。

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).

我试过的唯一方法到目前为止是从内部SQLite数据库中选择。这有效,但由于数据库非常大(大约35000个条目),因此速度非常慢。每次键入内容时,应用程序会在显示新建议之前冻结4或5秒。所以我猜这种方法并不是最好的。

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.

我在考虑将所有内容映射到NSDictionary中,但我担心桌子太大(约1.5MB)永久保留NSDictionary在内存方面是非常昂贵的。

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?

推荐答案

您是否考虑过使用NSThread创建将由表视图使用的数组? (尽管如此,不要做任何UIKit通话)。如果你在主线程上运行它,它会慢一点,特别是因为你的数据库很大。

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.

如果你不知道NSThread如何工作,检查这个很棒的教程: http://www.xprogress.com/post-36-threading-tutorial-using-nsthread-in-iphone-sdk-objective-c/

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/

这篇关于UITextField从大型数据库自动建议的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆