5

谁能给我指出我应该如何做到这一点的正确方向:

在此处输入图像描述

这个来自天气频道的示例显示了我想做的事情。我只想有一个表格视图,有人可以在其中搜索一个城市。我不确定从哪里获得这些资源以及如何获得这些资源。

4

2 回答 2

2

您可以从MaxMind找到世界城市列表。

是你要找的资源吗?

于 2012-06-28T01:31:45.943 回答
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];
}

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

我想这会对你有所帮助。

于 2012-06-28T04:40:26.830 回答