I have a UIViewController
setup in a storyboard with a tableview
and UISearchDisplayController
.
I am trying to use a custom prototype cell from self.tableview (which is connected to main tableview in the storyboard). It works fine if self.tableview
had returned at least 1 cell when I load my view, but if self.tableview
doesn't load a cell (as there is no data), and I load up the UISearchBar
and search, the cellForRowAtIndexPath:
method crashes:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
CustomSearchCell *cell = [self.tableView dequeueReusableCellWithIdentifier:@"CustomSearchCell" forIndexPath:indexPath];
[self configureCell:cell atIndexPath:indexPath];
return cell;
}
-(void)configureCell:(CustomSearchCell *)cell atIndexPath:(NSIndexPath *)indexPath {
User *user = [self.fetchedResultsController objectAtIndexPath:indexPath];
cell.nameLabel.text = user.username;
}
Errors:
*** Assertion failure in -[UITableViewRowData rectForRow:inSection:heightCanBeGuessed:]
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'request for rect at invalid index path (<NSIndexPath: 0x9ef3d00> {length = 2, path = 0 - 0})
My fetchedResultsController seems to have data (1 section, 2 rows) at the point the above method is called. It crashes on the dequeueReusableCellWithIdentifier
line.
Any pointers/ideas? It should dequeue the prototype cell from self.tableview
, but my guess is there was none created in self.tableview
so this is the cause?
configureCell:atIndexPath:
method? The problem may be in there – Lucas EduardodequeueReusableCellWithIdentifier
you must checkif (cell == nil)
, and if so, you need to create a cell. – ott--