maytime
maytime

Reputation: 121

How do you make prepareForReuse() work right?

I have a table view with ten cells. Each of them contains an image view. When scrolling, sometimes images start jumping from one cell to another - I guess reuse does not work. I tried to reset the image to nil in prepareForReuse(), but the problem persists.

catImageView.image = nil

I also reset indexPath in cellForRowAt, but that didn't work either.

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    guard let cell = tableView.dequeueReusableCell(withIdentifier: SearchCell.identifier, for: indexPath) as? SearchCell else { return UITableViewCell() }
    let cat = cats[indexPath.row]
    cell.setup(cat)
    cell.catImageView.image = nil
    return cell
}

In rxSwift for this I cleaned disposedBag. What can be done in this case?

Upvotes: 0

Views: 233

Answers (0)

Related Questions