Collection-View-in-a-Table-View-Cell
Collection-View-in-a-Table-View-Cell copied to clipboard
Reusing tableview cell
Hi, When scrolling the collectioview inside the cell and then scrolling the tableview, the cell that gets reused shows the the collection view scrolled to the position that i scrolled to in the first cell.
I was assuming that the storedOffsets was for this unwanted behavior. Unfortunately it is not working. Or is the storedOffsets for another issue?
Please help.
Hmm, good question. The reused cell should have its offset set to zero (as long as it doesn't haven't a preciously stored offset, see this line). I'm not sure what could be causing the issue you're seeing. I'll have a think.
Having this issue as well.
I had the same issue but fixed it by changing tableViewCell.collectionViewOffset = storedOffsets[indexPath.row] ?? 0 to tableViewCell.collectionViewOffset = storedOffsets[indexPath.section] ?? 0 I hope this helps!
Thanks for following up with your solution – it sounds like that would work for a multi-section, single-row table view instead of a single-section, multi-row. Is that the case @ClintonAkins?
You're right. This solution is for a mulit-section, single-row UI, like Netfilx, App Store, etc.
Fab, thanks again for the follow-up! going to keep this issue open to help people notice :tada:
One of the solution that worked for me was setting the contentOffset as
var collectionViewOffset: CGFloat { get { return productCollectionView.contentOffset.x } set { productCollectionView.setContentOffset(CGPoint(x: newValue, y: 0 ), animated: false) } }