I'm using a simple search display controller. I'm getting this error i have no idea. Here is the code plsss help n thanks!!!!!
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
NSInteger rows = 0;
if([tableView isEqual:self.searchDisplayController.searchResultsTableView])
{
rows = [self.searchResults count];
}
else
{
rows = [self.allItems count];
}
return rows;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
if([tableView isEqual:self.searchDisplayController.searchResultsTableView])
{
cell.textLabel.text = [self.searchResults objectAtIndex:indexPath.row];
}
else
{
cell.textLabel.text = [self.allItems objectAtIndex:indexPath.row];
}
return cell;
NSLog(@"the contents of cell are :%@",cell.textLabel.text);
}
-(void) filterContentsForSearchText:(NSString *)searchText scope:(NSString *)scope
{
NSPredicate *resultsPredicate = [NSPredicate predicateWithFormat:@"SELF contains[cd] %@",searchText];
self.searchResults = [self.allItems filteredArrayUsingPredicate:resultsPredicate];
}
//UISearchDisplayController delegate methods
- (BOOL)searchDisplayController:(UISearchDisplayController *)controller shouldReloadTableForSearchString:(NSString *)searchString
{
[self filterContentsForSearchText:searchString scope: [[self.searchDisplayController.searchBar scopeButtonTitles] objectAtIndex: [self.searchDisplayController.searchBar selectedScopeButtonIndex]]];
return YES;
}
-(BOOL)searchDisplayController:(UISearchDisplayController *) controller shouldReloadTableForSearchScope:(NSInteger)searchOption
{
[self filterContentsForSearchText:[self.searchDisplayController.searchBar text] scope:[[self.searchDisplayController.searchBar scopeButtonTitles] objectAtIndex:searchOption]];
return YES;
}
The error is as follows:
2012-03-08 15:37:18.905 SearchViewController[1082:fe03] * Assertion failure in -[UISearchResultsTableView _createPreparedCellForGlobalRow:withIndexPath:], /SourceCache/UIKit_Sim/UIKit-1912.3/UITableView.m:6072 2012-03-08 15:37:18.907 SearchViewController[1082:fe03] * Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'UITableView dataSource must return a cell from tableView:cellForRowAtIndexPath:'