2
我在我的应用程序中实现了一个集合视图。从集合视图中删除项目后的标记问题
收集单元格包含一个称为删除按钮的项目按钮。 删除一个项目后,标签没有更新,所以,如果我删除了第二个项目,那么它将删除它旁边的标签。
我的代码如下:
- (UICollectionViewCell *)collectionView:(UICollectionView *)cv cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"GradientCell";
UICollectionViewCell *cell = [cv dequeueReusableCellWithReuseIdentifier:CellIdentifier forIndexPath:indexPath];
UIButton *btn_close=[UIButton buttonWithType:UIButtonTypeCustom];
[btn_close setFrame:CGRectMake(50, 00, 18, 18)];
[btn_close setBackgroundImage:[UIImage imageNamed:@"close.png"] forState:UIControlStateNormal];
[btn_close addTarget:self action:@selector(delete_image:) forControlEvents:UIControlEventTouchUpInside];
btn_close.tag=indexPath.row;
return cell;
}
-(void)delete_image:(UIButton*)sender
{
[self.col_view performBatchUpdates:^{
[arr_images removeObjectAtIndex:sender.tag];
NSIndexPath *indexPath =[NSIndexPath indexPathForRow:sender.tag inSection:0];
[self.col_view deleteItemsAtIndexPaths:[NSArray arrayWithObject:indexPath]];
} completion:^(BOOL finished) {
}];
}