问题描述
我有一个集合视图,我尝试从didSelect方法的集合视图中删除一个单元格。我成功地使用以下方法
I have a collection view,and I tried to delete a cell from collection view on didSelect method.I succeeded in that using the following method
[colleVIew deleteItemsAtIndexPaths:[NSArray arrayWithObject:indexPath]];
但现在我需要从CollectionView Cell中删除按钮上的项目。这里我只得到indexpath 。行。
由此我无法删除该项目。
我试过这样。
But now I need to delete the item on button click from CollectionView Cell.Here I get only the indexpath.row.From this I am not able to delete the Item.I tried like this.
-(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.So删除后的单元格排列动画不在这里。
请提出建议..谢谢提前
But it needs to reload the CollectionView.So the animation of cell arrangement after deletion is not there.Please suggest an idea..thanks in advance
推荐答案
-(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) {
}];
}
试试这个。它可能适合你。
Try this. It may work for you.
这篇关于如何使用indexpath.row从UICollectionView中删除项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!