iosobjective-cuitableview

Attempted to dequeue multiple cells for the same index path, which is not allowed


I have a very simple UITableView that has worked just fine since iOS6....I have recently tried to make a new build going from iOS10-iOS11 and now I am getting this new NSInternalConsistency Exception that I have never seen before, it literally came out of left field with the new iOS build....

*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Attempted to dequeue multiple cells for the same index path, which is not allowed. If you really need to dequeue more cells than the table view is requesting, use the -dequeueReusableCellWithIdentifier: method (without an index path). Cell identifier: WorkOrderCell, index path: {length = 2, path = 0 - 0}'

I have reviewed numerous tutorials and I feel like there is nothing exceptionally wrong with this code..in fact normal grid load works fine, here is my code:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{

    UITableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier:@"WorkOrderCell" forIndexPath:indexPath];



    // Configure the cell...  do some work, return it



    return cell;
}

Has anyone else experienced this issue and what have you done to resolve it?

I should be a bit more specific, the normal UITableView does load fine, this specific issues is that I have a SearchBar, and when the user types into the search, I am filtering the results and displaying a results grid:

//Start Search/Filter Code
- (void)filterContentForSearchText:(NSString*)searchText scope:(NSString*)scope
{
    NSPredicate *resultPredicate = [NSPredicate predicateWithFormat:@"Job contains[cd] %@ or Address contains[cd] %@ or WorkOrderId contains[cd] %@ or Supervisor contains[cd] %@", searchText, searchText, searchText, searchText];
    self.filteredWorkOrders = [self.workOrders filteredArrayUsingPredicate:resultPredicate];
}


-(BOOL)searchDisplayController:(UISearchDisplayController *)controller shouldReloadTableForSearchString:(NSString *)searchString
{
    [self filterContentForSearchText:searchString
                               scope:[[self.searchDisplayController.searchBar scopeButtonTitles]
                                      objectAtIndex:[self.searchDisplayController.searchBar
                                                     selectedScopeButtonIndex]]];

    return YES;
}

The filter code itself works fine, it's just that it triggers the UITableView delegates to fire, which starts dequeuing cells (which should be empty right in the search results grid??)

In any event I could use some help with this one please.....


Solution

  • Don't use self.tableView in your cellForRowAtIndexPath method (or any of the other data source and delegate methods). Use the tableView parameter.

    This is really important when your data source and delegate methods are being used for more than one table view.