# [Swift] prepareForReuse()

If you have images loading in to your cell and you’re scrolling through fast and your internet connection isn’t the best, you’ll start noticing some images are where they shouldn’t be. This is because we are reusing cells, so the text and images are being rolled over, leading to the wrong images in the wrong cells.

All we need to do to is use the prepareForReuse() function in the custom cell. This function is called before cell reuse, letting you cancel current requests and perform a ‘reset’.

override func prepareForReuse() {
    tabTitle.text = ""
    tabIcon.image = nil

Now your table view scrolling will be smooth (through cell reuse) and incorrect images will not carry over (through prepareForReuse()).

# References

Apple Developer Document (opens new window)

Custom Cell을 재사용할 때 생기는 문제점 (opens new window)