2012-06-28 105 views
5

名單誰能給我一個正確的方向上的點,我應該怎麼做:搜索城市

enter image description here

這從天氣頻道樣本顯示我想做些什麼。我只想擁有一個可以搜索某個城市的桌面視圖。我不知道在哪裏獲得這些資源以及如何去做。

+0

調查UISearchDisplayController。這實際上是他們從一系列城市中讀取的桌面視圖。 :)鏈接到蘋果的文檔:[UISearchDisplayController](http://developer.apple.com/library/ios/#DOCUMENTATION/UIKit/Reference/UISearchDisplayController_Class/Reference/Reference.html)哦,如果我沒記錯你我正在運行我看到的iOS 6測試版。 (導航欄將其提供。) – erran

+0

@ipwnstuff Oooops!感謝編輯圖像:P,並且您是否有機會知道他們使用的是什麼來源? – sridvijay

+0

我不知道,但@Greg王添加了一個列表。 – erran

回答

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

我給你不完整的方法,你可以實現你想要做的。

我認爲這會對您有所幫助。