简体   繁体   中英

Get indexPath of cell when it's being shown from collectionView

I need to get an indexPath of the cell which will be shown (something like viewWillAppear: there is 1 or 2 cells shown at the time, paging is enabled).

I can't find any method/delegate which will tell me that cells were moved and indexPath XYZ will be shown now. Any help please?

edit: I have a label above collectionView where i want to display information about currently shown cell. The problem is I don't know where to send information from the cell to the label, that exactly this cell is now being displayed.

Try using cellForItemAtIndexPath ... It will be called everytime a cell will be shown, even if it was shown before.

Did that answer your question? If not, please provide some code, cheers :)

最好的解决方案(使用分页时)是使用collectionView:didEndDisplayingCell:forItemAtIndexPath:并在其中collectionView:didEndDisplayingCell:forItemAtIndexPath:以下行:

NSIndexPath *visibleIndexPath = [myCollectionView indexPathsForVisibleItems].firstObject;

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