【问题标题】:Remove space between cell and header删除单元格和标题之间的空间
【发布时间】:2015-03-24 14:26:09
【问题描述】:

我创建了一个包含两个部分的 uitableview。然而,第二部分标题和第一部分中的最后一个单元格之间似乎有一些不需要的空间(见截图)。有谁知道如何删除它?

每个请求的代码:

func tableView(tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
    let  headerCell = tableView.dequeueReusableCellWithIdentifier("SectionHeader") as MyRentalsScetionsHeaders

    switch(section){
    case 0:
        headerCell.sectionName.text = "Upcoming"
        headerCell.backgroundColor = UIColor(red: 87/255.0, green: 189/255.0, blue: 135/255.0, alpha: 1)

    default:
        headerCell.sectionName.text = "Ended"
        headerCell.backgroundColor = UIColor(red: 203/255.0, green: 205/255.0, blue: 200/255.0, alpha: 1)
    }

    return headerCell
}

func tableView(tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
    switch(section){
    case 0:
        return 45.0
    default:
        return 30.0
    }
}

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

func tableView(tableView: UITableView, viewForFooterInSection section: Int) -> UIView? {
    return UIView(frame: CGRectZero)
}

编辑

我当前的解决方案是将页脚的高度设置为 0.00001,这是允许的。这并不是最理想的解决方案,但它看起来好多了:) 如果有人知道像素完美的解决方案,我会喜欢的!

【问题讨论】:

  • 发布你的 heightForHeader/heightForFooter 和 viewForHeader/viewForFooter 方法。
  • 当然 :) 查看更新后的帖子
  • 我认为标签的高度小于 30(第二个标题的高度)。尝试返回它的高度。

标签: ios uitableview swift


【解决方案1】:

选择 tableview 并在属性检查器中。可以选择设置页眉和页脚之间的空间。 22 是默认值。

【讨论】:

  • 我可以将空格设置为1,但为什么我不能将其设置为0?
【解决方案2】:

选择 TableView > 打开 Size Inspector > 将 SectionHeight of Header 设置为 0。

【讨论】: