UICollectionView cellForItem 调用不正确

UICollectionView cellForItem called not correctly

Xcode 8.2.1 将 Swift 2.2 迁移到 Swift 3

之后

UICollectionView 的 cellForItem 未正确调用,但在迁移之前工作正常

我有带水平 UICollectionViewFlowLayout 的 CollectionView 并设置 paging set true

UIViewController 的视图框架与 UICollectionView 的框架相同,也与页面应用程序的单元格框架相同(全尺寸)

当我向右滚动 UICollectionView 时,我在 cellForItem(UICollectionViewDataSource func) 中打印 indexPath.row

indexPath.row 在

之后打印

0, 3, 4, 5, 6, 7, 8, 9, 10

然后滚动到上次打印时的相反方向10

下一个 indexPath 是 7 但它应该是 9 因为最后调用的索引是 10

并滚动到显示

的第一个单元格

6, 5, 4, 3, 2, 1, 0 印刷

为什么会出现这种情况?

在 Swift 2.2 之前迁移,工作正常

在 Swift 3 或 iOS 10 之后是否有更改为 UICollectionView 或 UICollectionViewFlowLayout?

从 Swift 2.2

迁移到 Swift 3 后

UICollectionView In iOS10 预取设置为真(默认)

所以 cellForItem 没有被称为线性序列

我在这个 post little bites of cocoa

中得到了提示

预取是针对数据源而不是单元格

所以有时不会线性调用 cellForItem(这是针对单元格的)(我想要的)

只需取消选中预取,即可像迁移前一样正常工作