0

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.

Nat
  • 12,032
  • 9
  • 56
  • 103
  • unclear what you're asking. – Toseef Khilji Jan 16 '14 at 09:53
  • Don't you create those cells in the `UICollectionViewDataSource`? Therefore you know the cell that's being created. – trojanfoe Jan 16 '14 at 09:55
  • 1
    Possible duplicate - http://stackoverflow.com/questions/13176333/ios6-uicollectionview-and-uipagecontrol-how-to-get-visible-cell – Nayan Jan 16 '14 at 09:56
  • @NSS Yes, that's similar question. However method `scrollViewDidEndDecelerating` will not help, as it will update the label too late (we can see few other cells meantime, my label won't be updated). Other methods of `UIScrollView` also are not the best solution, as they update the information too often. – Nat Jan 16 '14 at 09:58
  • @trojanfoe I know which cell is being created, but i don't know which cell is being displayed. This is a different thing, as `UICollectionView` often deque a cell before displaying it. – Nat Jan 16 '14 at 10:00

2 Answers2

2

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

Abdullah Alharbi
  • 311
  • 1
  • 5
  • 9
  • I've shared code in my answer ;). `cellForItemAtIndexPath` be called, but nothing guarantees me that the visible cell will be the last one to be called - other cells may be called later and I'll override description for wrong cell. Thank you for your answer tho! – Nat Jan 16 '14 at 11:00
1

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

NSIndexPath *visibleIndexPath = [myCollectionView indexPathsForVisibleItems].firstObject;
Nat
  • 12,032
  • 9
  • 56
  • 103