cellForRowAtIndexPath始终返回最后一个单元格

时间:2017-10-05 15:08:22

标签: ios objective-c uitableview uicollectionview

我在tableView中有colletionViewCell,我在UILongPressGesture上也使用了collectionView

我想要实现的目标:

  1. 检测长按。 (完成)
  2. 判断longPress是否在collectionViewCelltableViewCell上(colectionViewCell也有空格,即tableView未涵盖的空格)(完成)
  3. 如果长按在collectionView上(不在tableView或tableViewCell上)(完成),请拍摄collectionViewCell的屏幕截图。
  4. 如果长按在桌面上,请拍摄tableViewCell的屏幕截图(未完成)
  5. 什么是错误的: tableView为indexPath返回的单元格总是错误的。下面是我的代码一步一步。

    从longPress locationInView:

    获取collectionViewCell的索引路径
    CGPoint collectionPoint = [longPressGesture locationInView:_collectionView];
    NSIndexPath *indexPath = [_collectionView indexPathForItemAtPoint:collectionPoint];
    

    使用

    获取collectionViewCell
    ColumnCollectionViewCell *cell = (ColumnCollectionViewCell*)[_collectionView cellForItemAtIndexPath:indexPath];
    

    返回正确的collectionViewCell

    使用

    查找tableViewCell的indexPath
    NSIndexPath *cardIndexPath = [cell.cardsTableView indexPathForRowAtPoint:[_collectionView convertPoint:collectionPoint toView:cell.cardsTableView]];
    

    这将返回100%正确的indexPath。我已经测试了几个案例.indexPath总是它需要的。

    但是当我做的时候

    UITableViewCell *cardCell = [cell.cardsTableView cellForRowAtIndexPath:indexPath];
    

    这回复了我错误的tableViewCell。

    重要提示:我有两个不同的自定义tableViewCells。让CustomCell1和CustomCell2

    tableView中只有最后一个单元格的类型为CustomCell2。这就是无论如何都会返回的细胞。

    例如:如果我将indexPath传递给row is 1 and section is 0,那么在视觉上它的CustomCell1(应该是)但返回的单元格是CustomCell2,它实际上位于indexPath (row = 3 section = 0)。

0 个答案:

没有答案