0
votes

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?

1

1 Answers

6
votes

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

enter image description here