首页 > 解决方案 > 如何快速将我的部分页脚粘贴在表格视图中一个特定页脚的末尾

问题描述

我在这里有一些部分,在第 1 部分,我有这个页脚作为附加信息。但是当我滚动屏幕时它会一直浮动。我该如何阻止它?如何将其保留在该部分下?我正在使用viewForFooterInSection,这是我的代码:

override func tableView(_ tableView: UITableView, viewForFooterInSection section: Int) -> UIView? {
    let footerView = UIView()
    if section == 1 {
        let label = UILabel()
        label.text = "A sticky footer here..."
        label.font = .systemFont(ofSize: 16)
        label.textColor = UIColor.gray
        label.backgroundColor = UIColor.clear
        label.textAlignment = .left
        footerView.addSubview(label)
        label.translatesAutoresizingMaskIntoConstraints = false
        label.topAnchor.constraint(equalTo: footerView.topAnchor, constant: 10).isActive = true
        label.leftAnchor.constraint(equalTo: footerView.leftAnchor, constant: 20).isActive = true
        label.rightAnchor.constraint(equalTo: footerView.rightAnchor).isActive = true
        label.bottomAnchor.constraint(equalTo: footerView.bottomAnchor).isActive = true
    }
    return footerView
}

我想保持粘性,在我的第 1 部分下。我该怎么做?

先感谢您

在此处输入图像描述

标签: iosswiftheadertableviewfooter

解决方案


您应该使用分组样式初始化表格视图。

let tableView = UITableView(frame: .zero, style: .grouped)


推荐阅读