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