Why am I scroll first cell then third cell also scrolling?
Asked
Active
Viewed 53 times
-2
-
Please add relevant code. – iVarun Sep 03 '18 at 07:38
-
This is happening because of cell reuse. You'll need to have some persistent data for every separate cell that will be triggered on cellForRow. – Stefan Sep 03 '18 at 07:39
-
Explain your problem, show some of your code - https://stackoverflow.com/help/how-to-ask – teja_D Sep 03 '18 at 07:40
1 Answers
1
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)
}

Ladislav
- 7,223
- 5
- 27
- 31