简体   繁体   中英

iOS TableView inside of a CollectionView sometimes shows incorrect data

I have a collectionView where I show a list of comments in a tableView. I see that the tableView data is not the correct one when the collectionView is scrolled.

I tried to remedy that using prepareForReuse() which did not work. Here is my code :

override func prepareForReuse() {
        super.prepareForReuse()
        imageView.image = UIImage()
        commentsTableView = UITableView()
    }

I would appreciate if someone can suggest a solution for this.

Thanks.

Assign all your properties to nil.

override func prepareForReuse() {

        imageView.image = nil
        commentsTableView = nil
        super.prepareForReuse()
    }

But make sure that your properties is optional.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM