我的 UICollectionView 的 IndexPath 错误

Wrong IndexPath of my UICollectionView

我的 UICollectionView 有问题。

我用 2 个列表创建了我的 collectionView。 这 2 个列表包含每个列表的 header。 例如,当我单击第一个列表中的第一个单元格时,我的代码会向我发送 indexPath.item = 0。一切正常。 但是当我点击第二个列表中的第一个索引时,我的索引也是 returns 0 ,但我更喜欢它在第一个列表之后。

例如,如果我的第一个列表中有 10 个项目 (indexPath 0 -> 9) 我希望第二个列表的第一个 object 等于 到 10 而不是从头开始!提前谢谢你。

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
    }
}

可以在每个列表中使用tags,需要取值的时候再去查看,比如

if (list.tag == 0 && indexPath.item = 0){
   //list 1 and indexPath.item is 0
} 

if (list.tag == 1 && indexPath.item = 0){
   //list 2 and indexPath.item is 10
}

我不知道是否有办法直接获取此值,因为您正在创建一组新的 CollcetionViewCell。您也可以根据部分进行跟踪。

IndexPath 为单元格提供有关它在 collectionView 中的位置的信息。单元格索引可以通过其在 NSIndexPath 中的 sectionitem 属性来标识。使用这些属性的组合来确定确切位置。