代码之家  ›  专栏  ›  技术社区  ›  Creator

cellForItemAtIndexPath在块中获取了错误的indexPath值

  •  0
  • Creator  · 技术社区  · 8 年前

    UICollectionViewCell

    @interface MYCollectionViewCell : UICollectionViewCell
    @property (nonatomic, copy) void (^clickButtonBlock)(BOOL boolValue);
    @end
    

    我将块设置为删除单元格,单击 cellForItemAtIndexPath ,例如:

    [self.collectionView performBatchUpdates:^{
        [strongSelf.dataArray removeObjectAtIndex:index];
        [strongSelf.collectionView deleteItemsAtIndexPaths:@[[NSIndexPath indexPathForRow:index inSection:0]]];
        [strongSelf.collectionView insertItemsAtIndexPaths:@[[NSIndexPath indexPathForRow:5 inSection:0]]];
    }];
    

    删除第一个单元格后。下一个单元格的 NSIndexPath 是错误的,函数 [collectionView indexPathForCell:strongCell]; 在块中获取正确的值。

    1 回复  |  直到 8 年前
        1
  •  2
  •   Kapil G    8 年前

    你没有打电话 collectionView.reloadData()