Reusing cells in UITableView

后端 未结 1 1927
佛祖请我去吃肉
佛祖请我去吃肉 2021-01-24 04:30

I have my custom cell \'NewsCell\'. It contains my custom view \'ImageMosaicView\' (that is just subclass of UIView). I use it to show photos like in post in Facebook. I just pa

1条回答
  •  梦毁少年i
    2021-01-24 04:55

    The right way to do this is to configure the prepareForReuse() method inside the NewsCell class.

    override func prepareForReuse() {
        super.prepareForReuse()
    
        imageView.image = //Default image
        //Whatever other things you need cleared.
    }
    

    This method is called whenever a tableView dequeues a cell. So any cached data should be cleared here or it will persist in the dequeued cell unless you manually change it before returning it in the cellForRowAt method.

    0 讨论(0)
提交回复
热议问题