开发者

how to create a searchbar like in the weather app?

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 w开发者_运维知识库hich 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.


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.


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.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜