I am trying to implement search for UITableView. First I fill my array of historical periods from DB in - (void)viewDidLoad method.
self.periodsArr=[dbAccsess getPeriods:subCountryID];
self.searchBar = [[[UISearchBar alloc]initWithFrame:
CGRectMake(0.0f, 0.0f, 320.0f, 44.0f)] autorelease];
searchBar.delegate=self;
self.tableView.tableHeaderView = self.searchBar;
searchBar.keyboardType=UIKeyboardTypeNumberPad;
self.searchController = [[[UISearchDisplayController alloc]
initWithSearchBar:self.searchBar contentsController:self] autorelease];
self.searchController.searchResultsDataSource = self;
self.searchController.searchResultsDelegate = self;
Then I try to implement method
- (NSInteger)tableView:(UITableView *)utableView numberOfRowsInSection:(NSInteger)section
{
if(utableView==self.tableView)
{
return [self.periodsArr count];
}
NSPredicate *predicate = [NSPredicate predicateWithFormat:
@"period beginswith[c] %@", self.searchBar.text];
filteredItems=[[NSMutableArray alloc]init];
self.filteredItems=[self.periodsArr filteredArrayUsingPredicate:predicate];
return filteredItems.count;
}
And in the View Controller UISearchBarDelegate,UITableViewDataSource,UITableViewDelegate
The strings in the tableCells are beginning with dates like 1789-1798. When I am trying to search the information, the search methods works only for first number.... for example I have a cell with information beginning with number 5. When I type in UISearchBar digit 5, the method returns me the record beginning with 1. When I type two numbers, method returns me 'no results'. Where's the problem and where I went wrong?
Well, I solved this issue by myself. I was screwed up in cellForRowAtIndexPath meth.