ios - 如何删除特定的 UICollectionViewCell 图像。按下特定图像上的按钮时

标签 ios objective-c uicollectionview

大家好,请帮帮我: 当我在这个 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/

相关文章:

iOS 7 UIWebView 拦截警报

iphone - NSNumber 存储在 NSUserDefaults 中

ios - SwiftUI 如何更改 keyUp macOS 事件的状态?

ios - 过渡动画中的闪烁(模拟器?)

ios - 循环播放 AVPlayer 视频流并刷新每次循环的比特率

ios - 如何将 UIView 限制为 UICollectionViewCell

ios - Handler 中的数组计数

objective-c - 来自不同类的方法两次

ios - UICollectionView - insertItems(在 : indexPath) not working

json - Swift 3、Alamofire 4、JSON 字典 : Only displaying last JSON entry