Spot the bug
While scrolling fast, rows briefly show other rows' photos. Tap the line that causes it.
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {let cell = tableView.dequeueReusableCell(withIdentifier: "Photo", for: indexPath) as! PhotoCelllet item = items[indexPath.row]cell.titleLabel.text = item.titleImageLoader.shared.load(item.url) { image incell.photoView.image = image}return cell}
Hint 1 of 1
By the time the image arrives, which row does this cell show?
Choose an answer, then open Show answer below to check it.
Show answer
- Answer: line 6
cell.photoView.image = image
Line 6 sets the image on whatever row the reused cell shows by the time the load finishes. Save cell.itemID = item.id, check it in the completion, clear the image in prepareForReuse and cancel the old load.