CizooDev CizooDev - 2 months ago 23
Swift Question

Wrong IndexPath of my UICollectionView

I have a problem on my UICollectionView.

I create my collectionView with 2 lists.
The 2 lists contain a header for each ones.
For example when I click on the first cell on my first list, my code send me indexPath.item = 0. All is normal.
But when I click on the first index on my second list, my index also returns 0 ,but I prefer it following of the first list.

For example if I have 10 items in my first list (indexPath 0 -> 9) I would like the first object of my 2nd list is equal to 10 and not start from beginning ! Thank you in advance.

override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
if let cell = sender as? UICollectionViewCell,
indexPath = collectionView?.indexPathForCell(cell),
managePageViewController = segue.destinationViewController as? ManagePageViewController {
managePageViewController.videoList = dataSource.pictureOfVideo
managePageViewController.currentIndex = indexPath.item


enter image description here


IndexPath for a cell provides you information on where it is located in the collectionView. The cell index can be identified by its section and item properties in NSIndexPath. Use the combination of these properties to identify the exact location.