Utwórz widok tabeli i pasek wyszukiwania. Musisz wdrożyć swoich delegatów: 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];
}
muszę dać wam niekompletnych metod i można realizować to, co chcesz robić.
Myślę, że będzie to pomocne.
Sprawdź w UISearchDisplayController. W rzeczywistości jest to widok tabeli, który czytali z listy miast. :) Link do dokumentacji Apple: [UISearchDisplayController] (http://developer.apple.com/library/ios/#DOCUMENTATION/UIKit/Reference/UISearchDisplayController_Class/Reference/Reference.html) Aha, i jeśli się nie mylę, "uruchamiam wersję beta systemu iOS 6, którą widzę. (Pasek nawigacji daje to.) – erran
@ipwnstuff Oooops! Edytowane zdjęcie: P i czy przypadkiem nie wiesz, z jakiego źródła korzystają? – sridvijay
Nie mam pojęcia, ale @Greg Wang dodał listę. – erran