Tobi Kremer
Tobi Kremer

Reputation: 668

Wrong height of Container View in UITableView header

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!

Upvotes: 1

Views: 770

Answers (1)

Lai Xin Chu
Lai Xin Chu

Reputation: 2482

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:

Upvotes: 1

Related Questions