簡體   English   中英

uitableview willdisplaycell委托很奇怪

[英]uitableview willdisplaycell delegate is strange

我一直在圍繞tableview工作,並陷入以下問題。

據我了解, willDisplayCell委托方法應允許我訪問當前的單元格設計。

我的問題是:它無法正常工作。 當試圖顯示80個單元格時,該委托函數僅運行五次。 不管該函數如何,在委托函數中編寫一行代碼都可以使其正常工作。

這是我的代碼:

func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath) {
    if indexPath.row == comment_arr.count - 1 {
        print("end")
        // (1)self.comment_height.constant =  self.comment_table.contentSize.height + 30
    }
    // (2)self.comment_height.constant =  self.comment_table.contentSize.height + 30
}

如果(1)行存在,則無法使用。 但是,如果(2)行存在,則效果很好。

我如何使它工作?

首先獲取部分中的行數。 然后找到最后一個項目

let totalRow = tableView.numberOfRows(inSection: indexPath.section)
        if(indexPath.row == totalRow - 1)
        {
           print("end")
            return
        }
tableView(_ tableView: UITableView, 
         heightForRowAt indexPath: IndexPath) -> CGFloat

在willDisplayCell之前被調用

此處以完整和詳細的方式介紹了該主題: TableView方法

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM