开发者

Best way to search as you type with UISearchBar? [duplicate]

开发者 https://www.devze.com 2023-03-27 21:50 出处:网络
This question already has answers here: Closed 11 years ago. Possible Duplicate: How to detect a pause in input for UISearchBar/UITextField?
This question already has answers here: Closed 11 years ago.

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 see开发者_StackOverflow社区ms expensive.

EDIT:

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


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.


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.


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.


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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号