如何创建像天气应用程序中的搜索栏?

发布于 2024-11-08 14:12:30 字数 304 浏览 1 评论 0原文

在我的应用程序中,当您添加新城市时,我希望有一个像天气应用程序中那样的搜索栏。 我还想使用谷歌地理编码搜索城市/地点并解析结果,我已经知道如何完美地做到这一点。 为此我实际上有两个问题。

首先,如何创建一个看起来像天气应用程序或斯托克斯应用程序中的搜索栏?普通的搜索栏没有我可以使用的主题。他们是怎么做到的?

第二,我怎样才能成为那种即时/实时搜索的感觉? 我的意思是,当您开始输入时,它会开始搜索您输入的内容,就像您输入的每个字母一样,它会进行新的搜索,并在您停止输入后不久显示数据。 我无法对输入的每个字母进行查询,这会导致流量过多,而且我猜会花费很长时间。

in my app I want to have a searchbar like in the weather app when you add a new city.
I also want to search for citys/places with google geocoding and parse the results I already knkow how to do that works perfect.
for this actually I have two questions.

first how do I create a searchbar that looks like the one in the weather app or the stokes app? a normal searchbar does not have a topic which i can work with. How did they do that ?

and second how can I become that instant/live search feeling?
I mean that when you start typing it starts searching for what you typed in, kind a like for every letter you type it does a new search and presents data after a short while when you stopped typing.
I cant do a query for every letter typed in, that would cause too much traffic and would take too long I guess.

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

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

发布评论

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

评论(2

少女情怀诗 2024-11-15 14:12:30

创建基于窗口的项目,放置一个视图,放置一个 UISearchBar,在搜索栏顶部放置一个视图,将其设为矩形,这样您就拥有了一个带有主题的搜索栏。然后,您必须实现 UISearchBarDelegate 协议,以便每次编辑时,您都会在之前预加载(或直接从互联网)的字典中查找城市名称,并在有任何匹配项时执行表插入。您可以尝试匹配确切的名称,或使用 levenshtein 距离。

也许您只需要延迟后的实时结果,因此请

[NSObject cancelPreviousPerformRequestsWithTarget:self];
[self performSelector:@selector(fillMyTableWithResults) withObject:nil afterDelay:1.0];

在委托的 textDidChange 方法中执行此操作。

Create window based project, drop a view, drop a UISearchBar, drop a view on top of the search bar, make it rectangular, and you have a search bar with a topic. Then you have to implement the UISearchBarDelegate protocol so for each editing you look up the city names on a dictionary that you previously preloaded (or from internet directly) and perform a table insert if there is any matches. You can try to match the exact names, or use the levenshtein distance.

Probably you only want live results after a delay so do

[NSObject cancelPreviousPerformRequestsWithTarget:self];
[self performSelector:@selector(fillMyTableWithResults) withObject:nil afterDelay:1.0];

in the textDidChange method of the delegate.

郁金香雨 2024-11-15 14:12:30

你看过UISearchDisplayController吗?看一下这个示例

编辑
您可以考虑缓存以前的结果,但如果不发送请求,您最终可能会显示陈旧的数据。虽然我还没有真正尝试过,但我认为 Three20 框架是根据网络作为数据的理念构建的来源。它还有一个等效的 TTSearchDisplayController。你可以看看是否有帮助。

Have you looked at UISearchDisplayController. Take a look at this example.

EDIT
Caching previous results is something that you can consider but without sending a request, you can end up showing stale data. While I haven't actually tried it out, I think the Three20 framework as it is built with the idea of web as a data source. It also has an equivalent TTSearchDisplayController. You can see if it helps.

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