【问题标题】:How to delete UICollectionView Image one by one如何将 UICollectionView Image 一张一张删除
【发布时间】: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


    【解决方案1】:

    ok 像这样为你的 mybutton 设置一个标签

    [mybutton setTag: indexPath.row];
    
    -(void) delete :(id)sender{
        UIButton *btn = (UIButton *)sender;
        [_selectedAssetArray removeObjectAtIndex:btn.tag];
        //reload your collectionview here
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-04-03
      • 2012-01-07
      • 1970-01-01
      • 2014-07-11
      • 1970-01-01
      相关资源
      最近更新 更多