简体   繁体   English

UITableView reloadSections是否不会触发viewForFooterInSection?

[英]UITableView reloadSections does not trigger viewForFooterInSection?

I'm trying to build an app similar to iOS native Reminders app. 我正在尝试构建类似于iOS本机提醒应用程序的应用程序。 Where there's a list of items with header and footer. 哪里有带有页眉和页脚的项目列表。 Each cell contains an UITextView that will dynamic change cell height when user typing. 每个单元格都包含一个UITextView ,当用户键入内容时,它将动态更改单元格的高度。 Footer view contains the same cell view, except I want it to be a footer so it would stick to the bottom view. 页脚视图包含相同的单元格视图,但我希望它成为页脚,因此它会坚持到底部视图。 I have cell set to dynamic height. 我将单元格设置为动态高度。

checklistTable.rowHeight = UITableViewAutomaticDimension
checklistTable.estimatedRowHeight = 60

checklistTable.sectionFooterHeight = UITableViewAutomaticDimension
checklistTable.estimatedSectionFooterHeight = 60

here is the logic for update cell height while typing, this works perfectly for regular cells, but does not work for footer view. 这是键入时更新单元格高度的逻辑,这对常规单元格非常适用,但不适用于页脚视图。 I set an breakpoint in viewForFooterInSection, it was never called after initial loading. 我在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)
    }
}

Can anyone point me to the right direction? 谁能指出我正确的方向? Thanks 谢谢

Enabling & disabling animations on UIView & invoking tableView?.beginUpdates() simultaneously looks ambiguous . UIView上启用和禁用动画并调用tableView?.beginUpdates()同时看起来模棱两可
Simply, invoking reloadSections should work, like: 简单来说,调用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