Crea vista tabella e barra di ricerca. Devi implementare i loro delegati 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];
}
Ho dato a voi metodi incompleti e potete implementare ciò che volete fare.
Penso che sarà utile a voi.
fonte
2012-06-28 04:40:26
Cerca in UISearchDisplayController. In realtà è una tabella che hanno letto da una lista di città. :) Collegamento alla documentazione di Apple: [UISearchDisplayController] (http://developer.apple.com/library/ios/#DOCUMENTATION/UIKit/Reference/UISearchDisplayController_Class/Reference/Reference.html) Oh, e se non mi sbaglio tu Sto eseguendo la beta di iOS 6 che vedo. (La barra di navigazione lo consegna.) – erran
@ipwnstuff Oooops! Modificato l'immagine grazie: P e vorresti per caso sapere quale fonte stanno usando? – sridvijay
Non ho idea ma @Greg Wang ha aggiunto una lista. – erran