Search code examples
iphoneobjective-cuitableviewuisearchdisplaycontroller

Simplest way for UISearchDisplayController to show same cells as the origin


What's the simplest way to make UISearchDisplayController display exactly the same cells (formatting, height, fonts, colors, etc) as the original tableView that it searched on? or simply put - make it dequeue de same cell identifier?

I am using a the standard subclassed UITableViewController + UISearchDisplayController solution, and prefer to stick to it.

thanks


Solution

  • I actually found the simplest way.

    All I had to do is change the default cellForRowAtIndexPath second line of code and add the "self." to tableView to the dequeue cell identifier - this way the the cell style which is in the storyboard always gets dequeued and not the (non-existant) one from the searchResultsController.tableView

    Also implement heightForRowAtIndexPath that will return the same height without any check (searchresults table or self.table - we want the same height)

    -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
    {
        return 62.0f;
    }
    
    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
    {
        static NSString *CellIdentifier = @"PhraseCell";
        UITableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier:CellIdentifier];
        //                       ^^^^ NEW
    
        //...