Search for a list of cities

Can someone give me a point in the right direction, how should I do this:

enter image description here

This sample from the Weather Channel shows what I would like to do. I just want to have a view of the table in which someone could look for a city. I am not sure where to get these resources and how to do it.

+5
source share
2 answers

A list of world cities can be found in MaxMind .

Is this the resource you are looking for?

+2
source

Create a table and search bar. You must implement your delegates 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];
}

I give you incomplete methods, and you can implement what you want to do.

I think it will be useful for you.

+1
source

All Articles