如何避免在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")

这是非常糟糕的练习,会导致崩溃,具体取决于使用的数据

如果我是您,我将只维护当前的方式,但请确保在下载完成后将数据设置为正确的单元格

最新更新