Search code examples
swifttableviewcollectionview

swift CollectionView inside TableView Cell


Why am I scroll first cell then third cell also scrolling?

Screen Record


Solution

  • It is because of cell reuse, so basically the cell that you scroll goes off screen and will be reused when another cell down is needed.

    In your UITableViewCell subclass you can implement prepareForReuse method, this is called when cell is ready to be reused and you can set contentOffset to 0 there, something like:

    override func prepareForReuse() {
        super.prepareForReuse()
    
        scrollView.contentOffset = CGPoint(x: 0, y: 0)
    }