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.

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

From:
TalkListTableViewCell *cell = [tableViewdequeueReusableCellWithIdentifier:cellId];

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

However custom height cell’s may require more work. See:
http://stackoverflow.com/questions/15892651/uisearchdisplaycontroller-not-correctly-displaying-custom-cells

Leave a Reply