问题
Basically what I want to do in my app is have a UISearchBar
which, when I write in, will feedback location results and populate that into a UITableView that appears. I see one more question on this site:
Display Locations on UITableview
But that really didn't help me, no answer helped me at all, and they were quite vague.
So, my question is. You know how some apps maybe you have to type in a city or country, but the user might not be able to fully spell it, so based on your UISearchBar
results, it presents a TableView with the suggested cities. So say I am about to write Singapore, I don't know how it is spelled. So I write:
'Sing'
And BAM, a UITableView below pops up with different options/cell titles, including a cell that suggests 'Singapore'. Then I click on that cell and then my search bar is autofilled with 'Singapore'. Here is a screenshot example of what I want to do with a current app called 'iChangi' on the Singapore app store:

So I understand I should implement the UISearchBar
delegate where the text changed, but what I want to know is there an API or database I can query to feedback the suggested cities? And how would I go around doing this, can you provide me with a tutorial on it or simply state a few steps.
回答1:
Check this project http://iosboilerplate.com/#maps
回答2:
With the Help of Table view and search bar you can create presentation of City list. Now about API for city list there is many link availibale on Map for same. Please refer below
http://www.geonames.org/export/
https://developers.google.com/adwords/api/docs/appendix/cities_world
Download Table from above URL and place this with resource directory and use this for suggestion.
See more link for same
http://www.geodatasource.com/cities-free.html
http://weather.noaa.gov/data/nsd_cccc.txt
http://www.geonames.org/export/JSON-webservices.html#citiesJSON
回答3:
I know it's quite late, but maybe it can help others,
I've recently created autocomplete view
, which can be attached to any UITextField
, with single line of code. Colors, separators, margins can be configured. Ships with google locations completion source.
You can clone it from GitHub
回答4:
It looks like you want a UISearchDisplayController.
来源:https://stackoverflow.com/questions/10661707/displaying-suggested-locations-in-uitableview