1

我正在显示图像。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
}
4

2 回答 2

3

如果您也知道该部分:

NSIndexPath *indexPath = [NSIndexPath indexPathForRow:i inSection:0];
[self.colleVIew deleteItemsAtIndexPaths:[NSArray arrayWithObject:[indexPath]]];
于 2013-04-24T18:16:33.963 回答
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];
}
于 2013-04-24T21:20:24.823 回答