Wrong height of Container View in UITableView header

772 Views Asked by At

I have set up a UITableViewController with a Container View as header view in Interface Builder. The header view has a height of 180px:

enter image description here

Unfortunately, at run-time the height of the Container View is just 116px:

enter image description here

If I replace the Container View in the table head with a standard view, say UILabel, the height of the header view I set in Interface Builder is correctly honoured. But this somehow doesn't work with Container Views.

Adjust Scroll View Insets doesn't help because it just moves the overflowing part of the image under the Navigation Bar, the height of the Container view is still wrong.

Any ideas? Thanks!

1

There are 1 best solutions below

6
On

You should implement UITableViewDelegate and declare the method

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    return 180;
}

Reference: https://developer.apple.com/library/ios/documentation/UIKit/Reference/UITableViewDelegate_Protocol/#//apple_ref/occ/intfm/UITableViewDelegate/tableView:heightForHeaderInSection: