使用 UISearchBar 键入时进行搜索的最佳方式?

发布于 2024-11-29 07:52:34 字数 415 浏览 4 评论 0原文

可能的重复:
如何检测 UISearchBar/UITextField 输入中的暂停?

我有一个 UISearchDisplayController。目前,我正在向我的网络服务器发送一个字符串,它会返回一组结果。我希望能够“边输入边搜索”。

推荐的方法是什么?我应该逐个字符地访问服务器并返回结果吗?那看起来很贵。

编辑:

每个字符都会返回一整套结果。不仅仅是一个结果。

Possible Duplicate:
How to detect a pause in input for UISearchBar/UITextField?

I have a UISearchDisplayController. Currently I am sending a string to my webserver and it returns back with an array of results. I want to be able to "search as I type".

What is the recommended way of doing this? Should I hit the server character by character and return results? That seems expensive.

EDIT:

Each character returns a full set of results. Not just a single result.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(4

鹿童谣 2024-12-06 07:52:34

这几乎就是大多数应用程序的做法。

解决您对性能问题的最佳方法是进行一些基准测试。您可以进行调整,例如,直到他们输入至少 3 个字母后才开始搜索,仅每 2 个字母检查一次,等等。根据您正在处理的数据,缓存也可能是一种选择。或者,如果数据足够小并在设备上进行过滤,那么在进行搜索之前提取完整的数据集可能会更有意义。

This is pretty much how most applications do it.

The best way to answer your concerns about performance is to do some benchmarking. You can make adjustments, e.g. don't start searching until they've entered at least 3 letters, only check every 2 letters, and so forth. Depending on the data you're dealing with, caching could also be an option. Or maybe it'll make more sense to pull down the full data set prior to doing the search if the data is small enough and do the filtering on the device.

一刻暧昧 2024-12-06 07:52:34

很贵。但这只是唯一的方法。如果您有兴趣降低成本,请尝试(1)缓存,(2)在击键和请求之间添加一个小的延迟,以及(3)首先获取相关的客户端数据,例如“最近”,“收藏夹” “, 等等。

It's expensive. But that's just about the only way. If you're interested in lowering the cost, try (1) caching, (2) adding a small delay between the keystroke and the request, and (3) fetching relevant client-side data first, such as "recents", "favorites", and so on.

乙白 2024-12-06 07:52:34

您能让服务器返回包含第一个字符的所有结果的完整列表吗?如果没有,您将不得不一遍又一遍地访问服务器。如果您访问服务器并达到可以返回列表其余部分的程度,返回列表并让应用程序处理其余部分,这会有所帮助。

Can you afford to have the server return an entire list of all of the results with the first character? If not, you're going to have to hit the server over-and-over. It'll help a little if you hit the server and you reach a point where you can afford to return the rest of the list, return it and let the application handle the rest.

三生殊途 2024-12-06 07:52:34

当然太贵了。
将整个列表下载到客户端...
然后搜索列表。

Of course it's too expensive .
Download the whole list to client...
Then search the list.

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