这可能是由于单元格重用时没有正确重置图像视图而导致的。在设置图像视图时,应该在重新使用单元格之前将其设置为nil。以下是一个实例代码:
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath) as! CustomCell
cell.imageView.image = nil // 重置imageView
cell.imageView.sd_setImage(with: URL(string: imageURL), placeholderImage: UIImage(named: "placeholder")) // 设置新的图像
return cell
}
在这个例子中,我们使用了第三方库SDWebImage来异步加载图像。但无论何时,都应该在设置新的图像之前将imageView重置为nil,以确保现有的图像被正确清除。