【问题标题】:How can I remove space between tableview header and first cell?如何删除表格视图标题和第一个单元格之间的空间?
【发布时间】:2015-10-26 11:20:30
【问题描述】:

如何删除UITableView 标头和表格内容中的空格?

我尝试了以下方法,但在 tableview 标题后仍有空间

tableView.contentOffset = CGPointZero
self.automaticallyAdjustsScrollViewInsets = false
tableView.contentInset = UIEdgeInsetsMake(-20, 0, -20, 0)

【问题讨论】:

  • 你找到解决办法了吗??

标签: ios swift uitableview uikit


【解决方案1】:

您可以使用此代码删除标题并减少第一个单元格之间的空间,

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
 {
    return 0.005f;// set this according to that you want...
 }

你也可以如下设置页脚..

 - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
  return 3.5f;// also set this one as you want ...
}

【讨论】:

  • 除了使用 0.005f,还可以使用 FLT_EPSILON,它是最小的正浮点值。