UITableView section header height for non-grouped table

醉酒当歌 提交于 2019-12-03 09:47:24

Yes.

Use this delegate method:

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

Of course, change as appropriate. There's of course the one for footer as well:

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
    return 44;
}

At least since iOS 9 (tested) UITableView.sectionHeaderHeight is working for plain table views (non-grouped) as well!

You will get the default header height (usually 22.0).

Of course the table views delegate might have customized this default value in its tableView:heightForHeaderInSection: method.

The following code snippet gives the height of a defined section header:

CGFloat headerHeight = self.tableView.sectionHeaderHeight;
if ([self.tableView.delegate respondsToSelector:@selector(tableView:heightForHeaderInSection:)]) {
    // possibly custom header height
    headerHeight = [self.tableView.delegate tableView:self.tableView heightForHeaderInSection:indexPathForCell.section];
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!