简体   繁体   English

如何避免在TableView iOS Swift中滚动时刷新每个单元格数据?

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

I have tableView with custom cell. 我有带自定义单元格的tableView。 I load some information from the web services and add it to the table if user scroll table down. 如果用户向下滚动表,我将从Web服务中加载一些信息并将其添加到表中。 Problem: after loading information in cells data change while scrolling. 问题:在单元格中加载信息后,滚动时数据会更改。 There is my code: 有我的代码:

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
            }
        }
    }
}

If you don't want to reuse cells you can do it like this : 如果您不想重复使用单元格,可以这样做:

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

However this is very bad practice and will lead to crashes depending on how big the data used 但是,这是非常糟糕的做法,并且会导致崩溃,具体取决于所使用的数据量

if i were you i'd just maintain the current way but make sure on setting the data on cell on completion of download that it's the right cell 如果我是你,我只是保持当前的方式,但请确保在下载完成后在单元格上设置数据,这是正确的单元格

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在Swift iOS的TableView单元格中对齐文本 - How to align text in tableview cell in swift ios 在Swift中以不同的间隔刷新TableView单元格以从URL获取数据 - Refresh TableView Cell at different intervals in Swift to get data from URL 如何在iOS上添加拉动数据以刷新Tableview? - How to Append data on pull to refresh Tableview in ios? iOS Swift:当我滚动它时,Tableview数据消失了 - iOS Swift : Tableview data disappear when i scroll it 在iOS的Swift表格检视单元中的registerForPreviewing - registerForPreviewing in a tableview cell, iOS, Swift iOS在TableView单元格中快速显示UIButton - iOS swift UIButton in TableView Cell 当我在 swift iOS 中垂直滚动时,Tableview 单元格数据正在发生变化 - Tableview cells data is changing when I scroll vertically in swift iOS 如何处理表视图单元格中的全部打开/全部关闭,每个单元格在 iOS Swift 中有查看更多/查看更少选项 - How to handle open all/close all in tableview cell with each cell has View More/View less options in iOS Swift TableView单元格错误-iOS / Swift - TableView Cell Error - iOS/Swift 如何在swift 4中正确地在tableview控制器单元内的tableview中重新加载数据? - how to reload data in tableview inside tableview controller cell correctly in swift 4?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM