我正在collection view
上显示图片。我想删除button click
上的每个项目。现在我可以删除didSelect method
上的项目。
-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
[array removeObjectAtIndex:indexPath.row];
[self.colleVIew deleteItemsAtIndexPaths:[NSArray arrayWithObject:indexPath]];
}
我在CollectionCell
上放置了按钮,可以找到indexpath.row
on click
。但是如何删除
-(void)chat:(int)i
{
NSLog(@"index path%d",i);
[array removeObjectAtIndex:i]; // array object is getting removed,how to delete the CollectionviewCell
}
答案 0 :(得分:3)
如果您确实知道该部分:
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:i inSection:0];
[self.colleVIew deleteItemsAtIndexPaths:[NSArray arrayWithObject:[indexPath]]];
答案 1 :(得分:1)
只需reloadData
,并确保array
中使用了numberOfItemsInSection
。这将重新加载dataSource
。
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
return [yourArray count];
}
-(void)chat:(int)i
{
NSLog(@"index path%d",i);
[yourArray removeObjectAtIndex:i];
// array object is getting removed,how to delete the CollectionviewCell
[self.collectionView reloadData];
}