UICollectionView cellForItemAt indexPath is skippi

2020-07-23 03:43发布

I have UICollectionView with horizontal scrolling and paging. When I scroll to next or previous page for the first time or change scrolling direction from left to right, value of indexPath.row in cellForItemAtIndexPath is changing by 3 not 1. Then it works properly. CollectionView works without problems in iOS 9. The problem occurs just in iOS 10. Thanks.

2条回答
在下西门庆
2楼-- · 2020-07-23 04:29

Problem was with new prefetching feature of UICollectionView. Disabling of prefetching solved my problem.

if #available(iOS 10.0, *) {collectionView.isPrefetchingEnabled = false}
查看更多
Explosion°爆炸
3楼-- · 2020-07-23 04:43

Possible Case:

Since you're using paging in your collectionView, and as your declaration, 1 page contains 3 cells. So if you move 1 page, the index of cell will move by 3 because the index the taking from the cell at the left.

E.g. Cell > Page 1:[0..1..2] Page 2:[3..4..5]

查看更多
登录 后发表回答