簡體   English   中英

UITableView在單擊單元格之前無法正確滾動到底部

[英]UITableView not scrolling properly to bottom until a cell is clicked

我有一個UITable視圖,該視圖在頂部有一個視圖,在下面有一些單元格。 這種等級制度

<tableview>
<view></view>
<cell></cell>
<cell></cell>
<cell></cell>
</tableview>

現在我將單元格設置為動態高度,因此它們會根據標簽高度進行擴展,現在在使用單行標簽時此方法可以正常工作,但是當我將標簽設置為0(多行)時,tableview會彈回頂部嘗試滾動,但是在此之后單擊這些單元格之一時,它會按原意滾動到底部單元格

在此處輸入圖片說明

我相對較新,所以請在回答時將其基本記住

提前致謝

這是填充單元格的代碼

   public func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell
    {

        myTableView.estimatedRowHeight = 50
        myTableView.rowHeight = UITableViewAutomaticDimension

        let cell = Bundle.main.loadNibNamed("ProfilerTableViewCell", owner: self, options: nil)?.first as! ProfilerTableViewCell

        cell.cellDescription.text = RatingsDataSet[n].descriptions[indexPath.row]
        if RatingsDataSet[n].valuesdata[indexPath.row][0] != "0" {
            cell.valueLabel.setTitle(RatingsDataSet[n].valuesdata[indexPath.row][0], for: .normal)
        }else{

            cell.valueLabel.setTitle("Not Set", for: .normal)
            cell.valueLabel.backgroundColor = UIColor.lightGray

        }

        return(cell)

    }

這兩行:

   myTableView.estimatedRowHeight = 50
   myTableView.rowHeight = UITableViewAutomaticDimension

屬於viewDidLoad() ,而不是它們所在的位置。 解決這些問題可能就是您要做的所有事情。

暫無
暫無

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

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