繁体   English   中英

UITableView reloadSections是否不会触发viewForFooterInSection?

[英]UITableView reloadSections does not trigger viewForFooterInSection?

我正在尝试构建类似于iOS本机提醒应用程序的应用程序。 哪里有带有页眉和页脚的项目列表。 每个单元格都包含一个UITextView ,当用户键入内容时,它将动态更改单元格的高度。 页脚视图包含相同的单元格视图,但我希望它成为页脚,因此它会坚持到底部视图。 我将单元格设置为动态高度。

checklistTable.rowHeight = UITableViewAutomaticDimension
checklistTable.estimatedRowHeight = 60

checklistTable.sectionFooterHeight = UITableViewAutomaticDimension
checklistTable.estimatedSectionFooterHeight = 60

这是键入时更新单元格高度的逻辑,这对常规单元格非常适用,但不适用于页脚视图。 我在viewForFooterInSection中设置了一个断点,它在初始加载后从未被调用过。

func textViewDidChange(_ textView: UITextView) {

    let startHeight = textView.frame.size.height
    let calcHeight = textView.sizeThatFits(textView.frame.size).height

    if startHeight != calcHeight {
        UIView.setAnimationsEnabled(false)
        tableView?.beginUpdates()

        if cellType == .footer {
            tableView?.reloadSections(IndexSet(integer: 0), with: .automatic)
        }

        tableView?.endUpdates()
        UIView.setAnimationsEnabled(true)
    }
}

谁能指出我正确的方向? 谢谢

UIView上启用和禁用动画并调用tableView?.beginUpdates()同时看起来模棱两可
简单来说,调用reloadSections应该可以,例如:

if startHeight != calcHeight {

        if cellType == .footer {
            tableView?.reloadSections(IndexSet(integer: 0), with: .automatic)
        }
    }

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM