UICollectionView cellForItemAt indexPath is skipping row indexes in iOS 10

萝らか妹 提交于 2020-02-01 06:20:31

问题


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.


回答1:


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

if #available(iOS 10.0, *) {collectionView.isPrefetchingEnabled = false}



回答2:


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]



来源:https://stackoverflow.com/questions/39871316/uicollectionview-cellforitemat-indexpath-is-skipping-row-indexes-in-ios-10

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!