Nat
Nat

Reputation: 12948

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.

Upvotes: 0

Views: 952

Answers (2)

Abdullah Alharbi
Abdullah Alharbi

Reputation: 331

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 :)

Upvotes: 2

Nat
Nat

Reputation: 12948

The best solution (when using paging) was to use collectionView:didEndDisplayingCell:forItemAtIndexPath: and this line inside:

NSIndexPath *visibleIndexPath = [myCollectionView indexPathsForVisibleItems].firstObject;

Upvotes: 1

Related Questions