简体   繁体   中英

iOS: cellForItemAtIndexPath returns nil even though cell is visible

I have a collection view and i have implemented drag and drop functionality. In addition, when cell is close to the top or bottom edges i scroll the collection with constant speed.

When i drag the cell i set its transform property according to the gesture and i also modify the value while scrolling. I also change the transform property of the layout attributes for the index path. The cell is always on the screen in the gesture position. However, at some point the collection decides to hide the cell and cellForItemAtIndexPath return nil.

Why does it happen and how can i prevent this situation?

I have the exact same problem. And I solve it by calling layoutIfNeeded following before asking for the reference to the cell.

self.collectionView.layoutIfNeeded()

See cellForItemAtIndexPath returns nil after force scrolling to make it visible

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM