[英]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.