UITableview中的部分之间的空间

我需要减lessUITableView两个部分之间的空间。 我看了这个问题,但解决scheme不允许我的自定义页眉视图,因为它结合了页脚和页眉的空间。

这里是UITableView的图片。 黑色是UITableView背景色。

桌面截图

你有没有尝试覆盖这个function:

  override func tableView(tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat { return 0.00001 } 

我认为你可以通过调整页脚视图的高度来达到它的最小值:在Storyboard或XIB中。 在这里输入图像说明

我不知道你已经写在你的代码页脚高度。 对不起,如果我错了。

在UITableView中隐藏页脚视图的可能重复

您需要使用方法heightForHeaderInSection来定义标题和单元格文本之间的空间。 您也可以根据不同部分进行更改,例如。 在某些部分,你可能需要展示更多的距离,在一些部分,你不想显示差距。 对于这种情况,您可以使用0.00001f的CGFLOAT_MIN。 给你一个例子,你如何使用不同的标题高度不同的部分

 - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section { if (section == 0 || section == 2) { return 55.0; } else { return CGFLOAT_MIN; } } 

希望它会帮助你。

对于Swift 3

 override func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat { return CGFloat.leastNormalMagnitude } 

你可以通过实现代表heightForHeaderInSectionheightForFooterInSection

返回值不应该是0,即使SectionHeader或SectionFooter的高度为0,也需要非常小的值,请尝试CGFLOAT_MIN

对于我的例子:

 - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{ if (section == [self.dataArray indexOfObject:self.bannerList]) { return 46; } return CGFLOAT_MIN; 

}

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

这也可能有助于:

 override func viewDidLoad() { super.viewDidLoad() tableView.sectionHeaderHeight = UITableViewAutomaticDimension }