簡體   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