UICollectionView cellForItem调用不正确 [英] UICollectionView cellForItem called not correctly

查看:70
本文介绍了UICollectionView cellForItem调用不正确的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

将Swift 2.2迁移到Swift 3后的Xcode 8.2.1



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



我有CollectionView with Horizo​​ntal UICollectionViewFlowLayout
和set 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在iOS10中预取设置为true(默认情况下)



所以cellForItem不是称为线性序列



我在这篇文章中得到了一个提示


Xcode 8.2.1 after migrate Swift 2.2 to Swift 3

UICollectionView's cellForItem not called correctly but before migration was working fine

I have CollectionView with Horizontal UICollectionViewFlowLayout and set paging set true

UIViewController's view frame is same to UICollectionView's frame also cell's frame like page application (full size)

I print indexPath.row in cellForItem(UICollectionViewDataSource func) when I scroll UICollectionView to right

indexPath.row printed following

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

then scroll to opposite direction when last printed 10

next indexPath is 7 but it should be 9 because last called index is 10

and scrolling until first cell showing

6, 5, 4, 3, 2, 1, 0 printed

why this situation happening?

In Swift 2.2 before migrate, work fine

is there a changing to UICollectionView or UICollectionViewFlowLayout after Swift 3 or iOS 10?

解决方案

After migrate to Swift 3 from Swift 2.2

UICollectionView In iOS10 prefetch set true (by default)

so cellForItem was not called as linear sequence

I get a hint in this post little bites of cocoa

prefetching is for datasource instead for cell

so somethimes not calling cellForItem(this is for cell) linearly (what i want)

just uncheck prefetching enable it works fine like before migration

这篇关于UICollectionView cellForItem调用不正确的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆