Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Crash when searching in two section

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! :)

like image 780
Antoine Gamond Avatar asked Jan 15 '13 10:01

Antoine Gamond


1 Answers

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

like image 73
kos Avatar answered Nov 16 '22 11:11

kos