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];
在块中获取正确的值。