【问题标题】:Remove space above inset grouped UITableView删除插入分组 UITableView 上方的空间
【发布时间】:2020-04-23 14:29:05
【问题描述】:

我有一个带有导航栏的表格视图控制器。我的表格视图是一个插入分组表格视图,每个部分都有标题。我正在尝试删除表格视图标题上方的空间。这是我的表格视图: 我该怎么做?

我试过了:

func tableView(tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
    return 0.1
}

但这不起作用。

【问题讨论】:

    标签: ios swift xcode uitableview


    【解决方案1】:

    适用于仍在寻找答案的任何人。该填充是由 UITableView 自己的标题引起的。这可以通过 tableHeaderView 属性进行设置。所以它看起来像这样:

    let tableView = UITableView(frame: CGRect(x: 0, y: 0, width: 10, height: 100), style: .grouped)
    tableView.tableHeaderView = UIView(frame: CGRect(x: 0, y: 0, width: 0, height: CGFloat.leastNonzeroMagnitude))
    

    height 设置为零将导致默认高度行为而不是实际大小为 0。

    【讨论】:

    • 上面的解决方案对我有用。第 0 部分的部分标题高度为 .leastNormalMagnitude,因为我不希望第一部分有标题,但其他标题为 .automaticDimesnsion,因为其他部分有标题。
    【解决方案2】:

    尝试从 tableviewcontroller 中删除方法 viewForHeaderInSection 它应该对你有帮助。

    override func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView?

    用这个方法,看起来像

    没有

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-04-17
      • 2012-04-13
      • 1970-01-01
      • 2023-04-01
      • 1970-01-01
      • 2012-01-11
      • 1970-01-01
      相关资源
      最近更新 更多