5
Q
搜索城市
A
回答
2
您可以從MaxMind找到世界城市列表。
它是您正在尋找的資源?
1
創建表格視圖和搜索欄。你必須執行他們的代表UISearchBarDelegate,UITableViewDataSource,UITableViewDelegate
。
- (void)searchBarTextDidBeginEditing:(UISearchBar *)searchBar1
{
searchBar.showsSearchResultsButton = YES;
searchBar.showsCancelButton = YES;
searchBar.autocorrectionType = UITextAutocorrectionTypeNo;
// flush the previous search content
//Implement some code
}
- (void)searchBarTextDidEndEditing:(UISearchBar *)searchBar1
{
searchBar.showsCancelButton = NO;
searchBar.showsSearchResultsButton = NO;
}
- (void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText
{
if([searchText isEqualToString:@""]||searchText==nil){
[yourTable reloadData];
return;
}
NSInteger counter = 0;
for(NSString *name in yourArray)
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc]init];
NSRange r = [name rangeOfString:searchText options:NSCaseInsensitiveSearch];
// NSRange r = [name rangeOfString:searchText];
// NSRange r = [name ];
if(r.location != NSNotFound)
{
//Implement the code.
}
counter++;
[pool release];
}
[yourTable reloadData];
}
- (void)searchBarCancelButtonClicked:(UISearchBar *)searchBar1
{
// if a valid search was entered but the user wanted to cancel, bring back the main list content
// Implement some code
@try{
[yourTable reloadData];
}
@catch(NSException *e){
}
[searchBar resignFirstResponder];
searchBar.text = @"";
}
- (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar1
{
[searchBar1 resignFirstResponder];
}
我給你不完整的方法,你可以實現你想要做的。
我認爲這會對您有所幫助。
相關問題
- 1. 實時搜索城市?
- 2. Facebook圖形API:按城市搜索
- 3. 按城市搜索Youtube視頻
- 4. 搜索城市狀態郵編
- 5. 在ios中搜索城市名稱
- 6. 搜索城市查詢所選類別
- 7. Google Place API按座標搜索城市
- 8. 搜索附近城市lat和長
- 9. 搜索從PlaceAutoComplete城市名稱給人加密的城市名稱
- 10. 檢索搜索字符串中的城市
- 11. 未能在Weatherlib API中檢索搜索到的城市android
- 12. MKReverseGeocoder返回不是城市的城市?
- 13. 在MapKit中搜索街道名稱,城市......的最佳方式?
- 14. 谷歌地圖搜索城市/州或郵編
- 15. 如何根據用戶搜索查找城市和國家?
- 16. HTML根據地址/城市搜索景點
- 17. 如何將facebook圖搜索限制爲僅限城市
- 18. 同一字段中的城市或郵政編碼搜索
- 19. 是否有任何城市全文搜索API?
- 20. 使用Typeahead.js搜索的城市沒有返回
- 21. 過濾google api來搜索特定城市的地理編碼
- 22. 搜索城市選項沒有出現在Android Studio
- 23. 在一個文本字段中搜索城市,州和郵編
- 24. Android地圖只能在城市內搜索
- 25. 如何使用Google Maps v3搜索某個地區的城市?
- 26. javascript中的城市/地址搜索自動完成
- 27. 在Facebook API中按城市搜索個人檔案
- 28. 如何執行谷歌地圖搜索街道名稱,城市?
- 29. 由城市,地址,狀態搜索,MLS數
- 30. 谷歌地圖api和跨區域城市搜索
調查UISearchDisplayController。這實際上是他們從一系列城市中讀取的桌面視圖。 :)鏈接到蘋果的文檔:[UISearchDisplayController](http://developer.apple.com/library/ios/#DOCUMENTATION/UIKit/Reference/UISearchDisplayController_Class/Reference/Reference.html)哦,如果我沒記錯你我正在運行我看到的iOS 6測試版。 (導航欄將其提供。) – erran
@ipwnstuff Oooops!感謝編輯圖像:P,並且您是否有機會知道他們使用的是什麼來源? – sridvijay
我不知道,但@Greg王添加了一個列表。 – erran