12

I have a NSFetchedResultController with different section. I have a crash when I try to search using UISearchDisplayController :

*** Assertion failure in -[UITableViewRowData rectForRow:inSection:], /SourceCache/UIKit/UIKit-2372/UITableViewRowData.m:1630

*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'request for rect at invalid index path (<NSIndexPath 0x1d2c4120> 2 indexes [0, 1])'

I checked and my search array has indeed two entries (the expected result):

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView

It returns 1

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section

It returns 2

Funny thing, if I have only one section, it works perfectly.

Help please! :)

Patrick
  • 1,629
  • 5
  • 23
  • 44
Antoine Gamond
  • 802
  • 1
  • 10
  • 19

1 Answers1

38

Not sure if you figured it out, I would think you did but assuming you are using

[self.tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];

in your cellForRowAtIndexPath

do

 if (tableView == self.searchDisplayController.searchResultsTableView) {
    cell = [self.tableView dequeueReusableCellWithIdentifier:CellIdentifier];
 } else {
    cell = [self.tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
 }

also make sure you are using self.tableView

kos
  • 1,357
  • 9
  • 21
  • 3
    Could you possibly explain the reason for this? Just wondering as I it may help me to solve another issue in the future. – WhoaItsAFactorial Oct 20 '13 at 21:52
  • 9
    This is because you are asking self.tableView for a cell. But the indexPath, when searching, is an index path into the search table. The index path isn't necessarily valid for self.table, so this index path can't be passed to it. self.table needs to be asked for the cell, as the CellIdentifier hasn't been registered with the search table. – Graham Perks Dec 02 '13 at 17:03
  • tableView and self.tableView really makes a difference. – tounaobun Jul 04 '15 at 07:44