我正在创建一个相机应用程序。我在集合视图中显示捕获的图片。我放了一个按钮来删除特定的图片。在运行时,我能够看到要删除的按钮,但是如果我单击该按钮则不会执行任何操作。
-(UICollectionViewCell *)collectionView:(UICollectionView *)
collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
CollectionViewCell *Cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"Cell" forIndexPath:indexPath];
Cell.self.image_View.image=[self.imageArray objectAtIndex:indexPath.row];
UIButton *deleteButton = [[UIButton alloc]init];
deleteButton.frame = CGRectMake(80, 0, 20, 20);
//deleteButton.backgroundColor = [UIColor redColor];
[deleteButton setImage:[UIImage imageNamed:@"delete.png"] forState:UIControlStateNormal];
[deleteButton setTag:indexPath.row];
[deleteButton addTarget:self action:@selector(delete:) forControlEvents:UIControlEventTouchUpInside];
[Cell.self.image_View addSubview:deleteButton];
return Cell;
}
-(void) delete:(UIButton*)sender{
UIButton *btn = (UIButton *)sender;
[self.imageArray removeObjectAtIndex:btn.tag];
//reload your collectionview here
}
任何人都可以帮助我吗?