Customizing UISearchDisplayController's row height

UISearchDisplayController is an elegant way to perform search on your UITableView controller,


but occasionally (99% of the time) you would want to customize the look and feel of the UITableViewCell, and when you changed the height of the rows, your UISearchDisplayController doesn't pick up the value automatically (because it is a separate view controller).

Which means when a user is searching with the UISearchBar, the rows in the search result has a different height than the table.

My first attempt is by just changing the height directly in viewDidLoad with the following:

self.searchDisplayController.searchResultsTableView.rowHeight = 82.0;

But this won't work because the searchResultsTableView is recreated automatically by the UISearchDisplayController when results are shown, and the above line won't get called again.

Thus, to overcome this we need to make sure whenever the result is shown, the above line will get executed. A quick search at iOS Developer Library shows that – searchDisplayController:didLoadSearchResultsTableView is exactly what I'm looking for.

So I put the following code in my implementation file (that implement UISearchDisplayDelegate).

- (void)searchDisplayController:(UISearchDisplayController *)controller didLoadSearchResultsTableView:(UITableView *)tableView {
    tableView.rowHeight = 82.0; // Change height of search result row
}
Update:
It appears that didShowSearchResultsTableView does not change the row height for the 1st search result, but didLoadSearchResultsTableView does the trick. I've updated the codes above to reflects the changes.

Comments

Popular posts from this blog

Generating INSERT statement from SELECT using SQuirreL SQL

OneNote: We need the password to sync this notebook (Error code: 0xE4010643)

Built-in UITableViewCell's Styles (UITableViewCellStyle)