如何避免在tableview ios swift中滚动刷新每个单元格数据?

时间:2018-04-04 04:37:27

标签: ios swift uitableview

我有自定义单元格的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
            }
        }
    }
}

1 个答案:

答案 0 :(得分:0)

如果您不想重复使用单元格,可以这样做:

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

然而,这是非常糟糕的做法,并会导致崩溃,具体取决于使用的数据量

如果我是你,我只是保持当前的方式,但确保在下载完成时在单元格上设置数据,这是正确的单元格

相关问题