我有一个 Collection View ,我尝试使用 didSelect 方法从 Collection View 中删除一个单元格。我使用以下方法成功了
[colleVIew deleteItemsAtIndexPaths:[NSArray arrayWithObject:indexPath]];
但现在我需要从 CollectionView Cell 中删除单击按钮时的项目。这里我只得到 indexpath.row。 由此我无法删除该项目。 我试过这样。
-(void)remove:(int)i {
NSLog(@"index path%d",i);
[array removeObjectAtIndex:i];
NSIndexPath *indexPath =[NSIndexPath indexPathForRow:i inSection:0];
[colleVIew deleteItemsAtIndexPaths:[NSArray arrayWithObject:indexPath]];
[colleVIew reloadData];
}
但是需要重新加载CollectionView,所以删除后的cell排列动画是没有的。 请提出一个想法..提前致谢
最佳答案
-(void)remove:(int)i {
[self.collectionObj performBatchUpdates:^{
[array removeObjectAtIndex:i];
NSIndexPath *indexPath =[NSIndexPath indexPathForRow:i inSection:0];
[self.collectionObj deleteItemsAtIndexPaths:[NSArray arrayWithObject:indexPath]];
} completion:^(BOOL finished) {
}];
}
试试这个。它可能对您有用。
关于iphone - 如何使用 indexpath.row 从 UICollectionView 中删除项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16296351/