2012-06-28 108 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]; 
} 

我给你不完整的方法,你可以实现你想要做的。

我认为这会对您有所帮助。