UISearchController and custom cells

I have just spent the last hour banging my head against the table and I thought I would blog about it incase others use UISearchDisplayController.

This allows you to add a nice search box to a UITableView, and is really easy to implement.

If you are using custom UITableViewCells, performing a search will not return the cell you think it is in cellForRowAtIndexPath.  It looks for a cell in the SearchController (not visible or in the storyboard), not your table that’s in the storyboard.

A simple fix that seems to work is. (fingers cross)

TalkListTableViewCell *cell = [tableViewdequeueReusableCellWithIdentifier:cellId];

TalkListTableViewCell *cell = [self.tableViewdequeueReusableCellWithIdentifier:cellId];

However custom height cell’s may require more work. See:

Leave a Reply