views:

248

answers:

2

I've set my UITableView row height to in Interface Builder to 54.0. I have a UISearchDisplayController on that view. When the user taps the search bar in it, the table resizes properly. However, when they start typing (and actually doing the search) the row height decreases. It stays wrong until the search taps Cancel.

I could find no documentation on this behavior on Apple's site.

I've tried setting the row height in UISearchDisplayDelegate delegate calls. This might be the right approach, but I don't know the details and couldn't get it to work.

I've also tried implementing - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath;. This worked, but I have thousands of entries in this list and can't take the performance hit.

What's the right way to fix this?

A: 

You need to set both

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {    
    return 54.;
}

and

self.tableView.rowHeight = 54.;

also in your UISearchDisplayDelegate

- (void)searchDisplayController:(UISearchDisplayController *)controller didShowSearchResultsTableView:(UITableView *)tableView {
    tableView.rowHeight = 54.; 
}

Otherwise, when "No Result" happened in searching, cell height will fall back to default.

digdog
Actually, heightForRowAtIndexPath: and .rowHeight behaves a little differently (at least in your case), so make sure you set them both, not just one of them.
digdog
I can't use heightForRowAtIndexPath. With 20,000 rows it slows down the table far too much on a real device.
Steven Fisher
+5  A: 

I found it!

Assuming the table is stored in tableView:

- (void)viewDidLoad;
{
    [super viewDidLoad];
    self.searchDisplayController.searchResultsTableView.rowHeight = tableView.rowHeight;
}

Nothing else is necessary.

Steven Fisher