【发布时间】:2014-08-20 07:32:50
【问题描述】:
当我按下删除按钮(红色小按钮)时,我希望这张图片删除并更新 UICollectionView。我为这个 collectionView 编写了这段代码。
-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
_cell=[collectionView dequeueReusableCellWithReuseIdentifier:@"cell" forIndexPath:indexPath];
_mainindex=indexPath;
UIImageView *imageview=[[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 70, 70)];
UIImage *img=_selectedAssetArray[_mainindex.row];
imageview.image=img;
imageview.userInteractionEnabled=YES;
[_cell.contentView addSubview:imageview];
UIButton *mybutton=[[UIButton alloc]initWithFrame:CGRectMake(50, -5, 30, 30)];
[mybutton setImage:[UIImage imageNamed:@"closeButton2.png"] forState:UIControlStateNormal];
[mybutton addTarget:self action:@selector(delete:) forControlEvents:UIControlEventTouchUpInside];
[imageview addSubview:mybutton];
return _cell;
}
在 didSelectItemAtIndexPath 中
-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
_mainindex=indexPath;
CropViewController *cropview=[[CropViewController alloc]initWithNibName:@"CropViewController" bundle:nil];
cropview.AftersaveArray=_selectedAssetArray;
cropview.CropIndex=_mainindex;
cropview.cropImage=[_selectedAssetArray objectAtIndex:indexPath.row];
cropview.CropImagedelegate=self;
[self presentViewController:cropview animated:YES completion:nil];
}
所以,我想在按下按钮时删除图像。
【问题讨论】:
标签: ios objective-c iphone xcode ios7