2

我正在尝试构建一个类似于 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)
    }
}

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

4

1 回答 1

2

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

if startHeight != calcHeight {

        if cellType == .footer {
            tableView?.reloadSections(IndexSet(integer: 0), with: .automatic)
        }
    }
于 2017-03-02T22:24:52.357 回答