I have an array of PFUsers and I'm trying to filter them based on local search results:
- (void)filterContentForSearchText:(NSString*)searchText scope:(NSString*)scope
{
NSPredicate *resultPredicate = [NSPredicate
predicateWithFormat:@"username contains[cd] %@",
searchText];
_searchResults = [[_messages filteredArrayUsingPredicate:resultPredicate] mutableCopy];
NSLog(@"_searchResults: %@",_searchResults);
}
But this doesn't work and ends up producing the following error:
'NSInternalInconsistencyException', reason: 'UITableView dataSource must return a cell from tableView:cellForRowAtIndexPath:'
Does anybody know what's wrong with my NSPredicate? Thank you!
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell;
if (cell == nil) {
cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
}
if (tableView == self.searchDisplayController.searchResultsTableView) {
NSLog(@"here?");
cell.textLabel.text = [_searchResults objectAtIndex:indexPath.row];
} else {
UILabel *name = (UILabel *)[cell viewWithTag:101];
if (_messages.count == 0)
name.text = @"No Messages";
else
name.text = @"name";
}
return cell;
}
I don't think the NSPredicate filter is working though...
NSPredicateerror, Can you show yourtableView:cellForRowAtIndexPathmethod?NSlogthe_searchResultsarray in thecellForRowAtIndexPathmethod and use breakpoints to prevent app from crashing._searchResultsarray infilterContentForSearchText:scope:? does it contain any value there? If no, then are you sure you have auserwith the same character sequence as thesearchText?