提问者:小点点

在表格视图中,如何使节页脚保持在一个特定页脚的末尾


我有一些章节在这里和第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个答案

匿名用户

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

让tableView=UITableView(框架:。zero,样式:。grouped)