为了设置高度为0,经常在tableView:heightForHeaderInSection方法返回0或者负数都无效,无论怎么改tableView的sectionHeaderHeight和estimatedSectionHeaderHeight属性也都无效。
有个办法就是在heightForHeaderInSection返回CGFLOAT_MIN,如下代码:
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
// Removes extra padding in Grouped style
return CGFLOAT_MIN;
}
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
// Removes extra padding in Grouped style
return CGFLOAT_MIN;
}
注意:
CGFLOAT_MIN在swift中的形式是CGFloat.min。设置tableView的
sectionHeaderHeight或estimatedSectionHeaderHeight为CGFLOAT_MIN都是无效的,最终还是要在tableView:heightForHeaderInSection方法返回CGFLOAT_MIN。