如何在天气应用中创建搜索栏? [英] how to create a searchbar like in the weather app?

查看:51
本文介绍了如何在天气应用中创建搜索栏?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用程序中,当您添加新城市时,我希望有一个类似于天气应用程序中的搜索栏.我也想用Google地理编码搜索城市/地方,并解析我已经知道如何完美运行的结果.为此,我实际上有两个问题.

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.

推荐答案

创建基于窗口的项目,拖放视图,拖放UISearchBar,在搜索栏顶部放置一个视图,使其变为矩形,然后便有了一个搜索栏有一个话题.然后,您必须实现UISearchBarDelegate协议,因此对于每次编辑,您都需要在先前预加载的词典中查找城市名称(或直接从互联网上),并在有匹配项时执行表格插入.您可以尝试匹配确切的名称,或使用 levenshtein 距离.

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];

在委托的textDidChange方法中.

in the textDidChange method of the delegate.

这篇关于如何在天气应用中创建搜索栏?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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