【发布时间】:2014-02-10 12:43:55
【问题描述】:
我在我的应用中实现了一个集合视图。
集合单元格包含一个名为删除项目的按钮。 删除一个项目后,标签不会更新,所以,如果我删除第二个项目,那么它将删除它旁边的一个,即标签。
我的代码如下:
- (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) {
}];
}
【问题讨论】:
标签: ios iphone objective-c uitableview uicollectionview