大家好,请帮帮我:
当我在这个 UICollectionView
中使用了一个 UICollectionView
时,我正在添加图像,我想在单击按钮时删除一个特定的图像。
我要删除的图像上有关闭按钮。
我怎么能完成这个任务。
笔记:
1) 请在帮助之前查看图像一次。
2)请看我添加图片的代码。
图片: My Image
//**** For image work ****
-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *ident = @"Cell";
OwnerPropertyCollectionViewCell *cell = (OwnerPropertyCollectionViewCell*)[collectionView dequeueReusableCellWithReuseIdentifier:ident forIndexPath:indexPath];
imgView = (UIImageView*)[cell viewWithTag:100];
if (indexPath.row ==0) {
cell.Imgprofile_pic.image = [UIImage imageNamed:[imgArray objectAtIndex:indexPath.row]];
cell.btnImageCancel.image = [UIImage imageNamed:@"add"];
UITapGestureRecognizer *reconizer = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(addphoto:)];
[cell addGestureRecognizer:reconizer];
}
else {
// get image not name
cell.Imgprofile_pic.image = [imgArray objectAtIndex:indexPath.row];
cell.btnImageCancel.image = [UIImage imageNamed:@"close"];
}
return cell;
}
// To add image:
-(void)addphoto:(UITapGestureRecognizer*)reconizer
{
imageHelper = [UIImagePickerHelper new];
[imageHelper imagePickerInViewController:self WithSuccess:^(UIImage *image) {
imgView.image = image;
[imgArray addObject:image];
[self.collectionView reloadData];
} failure:^(NSError *error) {
}];
NSLog(@"Image added successfully");
}
// What to code for delete image:
- (IBAction)btnCancelButtonAction:(id)sender {
NSLog(@"Delete button pressed");
}
最佳答案
将标签值作为所选删除按钮的单元格索引路径。(例如:第一行按钮标签将为 0) 然后从数组中删除该图像。然后重新加载你的 UICollectionView
[imgArray removeObjectAtIndex:index];
[self.collectionView reloadData];
关于ios - 如何删除特定的 UICollectionViewCell 图像。按下特定图像上的按钮时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41674379/