簡體   English   中英

如何避免在TableView iOS Swift中滾動時刷新每個單元格數據?

[英]how to avoid refresh each cell data on scroll in tableview ios swift?

我有帶自定義單元格的tableView。 如果用戶向下滾動表,我將從Web服務中加載一些信息並將其添加到表中。 問題:在單元格中加載信息后,滾動時數據會更改。 有我的代碼:

override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    if(indexPath.section == ProductDetailSectionId.ProductDetailView.rawValue) {
        if(self.productDetailModel != nil){
            if let cell = tableView.dequeueReusableCell(withIdentifier: "type1", for: indexPath) as? ProductDetailViewCell {
                cell.delegate = self
                cell.configureProductDetail(model: self.productDetailModel!)
                return cell
            }
        }
    }
}

如果您不想重復使用單元格,可以這樣做:

let cell = UITableViewCell(style: UITableViewCellStyle.default, reuseIdentifier: "CellReuseIdentifier")

但是,這是非常糟糕的做法,並且會導致崩潰,具體取決於所使用的數據量

如果我是你,我只是保持當前的方式,但請確保在下載完成后在單元格上設置數據,這是正確的單元格

暫無
暫無

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

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