简体   繁体   中英

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

I have tableView with custom cell. I load some information from the web services and add it to the table if user scroll table down. 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM