Reputation: 1526
Could anyone give me a point in the right direction on how I should do this:
This sample from the Weather Channel shows what I would like to do. I just want to have a Table View in which someone could search for a city. I'm not sure where to get those resources and how to do it.
Upvotes: 5
Views: 3979
Reputation: 6718
Create table view and search bar. You have to implement their 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 have give to you incomplete methods and you can implement what you want to do.
I think it will be helpful to you.
Upvotes: 1