Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/117.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 只能删除阵列中的一张图片_Ios_Arrays_Uicollectionview - Fatal编程技术网

Ios 只能删除阵列中的一张图片

Ios 只能删除阵列中的一张图片,ios,arrays,uicollectionview,Ios,Arrays,Uicollectionview,我正在使用集合视图删除阵列。这就是我想要它做的: 第一步:用户轻敲垃圾桶 第二步:收藏视图被购买,用户只需点击即可删除图片 然而,奇怪的是,我的代码只删除用户点击的第一张图片,而不删除从第二张图片开始的另一张图片。我不知道为什么会发生这种情况,我的删除过程代码是 -(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{ NSLog

我正在使用集合视图删除阵列。这就是我想要它做的:
第一步:用户轻敲垃圾桶
第二步:收藏视图被购买,用户只需点击即可删除图片

然而,奇怪的是,我的代码只删除用户点击的第一张图片,而不删除从第二张图片开始的另一张图片。我不知道为什么会发生这种情况,我的删除过程代码是

-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{

    NSLog(@"s:%d", [Trash count]);
    NSString *trashBin = [Trash objectAtIndex:indexPath.row];
    NSLog(@"k%@l",trashBin);
    [allImagesArray removeObjectAtIndex:indexPath.row];
    [self.collectionTrash reloadData];
    [self deleteMyFiles:trashBin];
}
NSString *myFileName;
-(void) deleteMyFiles:(NSString*)filePath {
    NSError *error;

    if([[NSFileManager defaultManager] fileExistsAtPath:filePath]) {
        [[NSFileManager defaultManager] removeItemAtPath:filePath error:&error];
    }
}
请随意索取更多代码

更新
你是说这个吗

-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{

    NSLog(@"s:%d", [Trash count]);
    NSString *trashBin = [Trash objectAtIndex:indexPath.row];
    NSLog(@"k%@l",trashBin);
    [allImagesArray removeObjectAtIndex:indexPath.row];
    [self deleteMyFiles:trashBin];
    [collectionView deleteItemsAtIndexPaths:[NSArray arrayWithObjects:indexPath, nil]];
}
NSString *myFileName;

-(void) deleteMyFiles:(NSString*)filePath {
    NSError *error;

    if([[NSFileManager defaultManager] fileExistsAtPath:filePath]) {
        [[NSFileManager defaultManager] removeItemAtPath:filePath error:&error];
    }
}
试一试
[allImagesArray removeObject:垃圾桶];如果要从数组中删除垃圾桶。

您可以通过调用
UICollectionView
类的
-deleteItemsAndExpaths
来删除所选垃圾桶,而不是重新加载整个collectionView

-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{

NSLog(@"s:%d", [Trash count]);
NSString *trashBin = [Trash objectAtIndex:indexPath.row];
NSLog(@"k%@l",trashBin);
[allImagesArray removeObjectAtIndex:indexPath.row];
[self deleteMyFiles:trashBin];
[collectionView deleteItemsAtIndexPaths:[NSArray arrayWithObjects:indexPath, nil]];

}

发布您的-(int)collectionView:(UICollectionView*)collectionView numberOfItemsInSection:(NSInteger)部分和collectionViewcell返回方法我已在此处显示了我的所有代码,请查看。谢谢我应该把它放在哪里?我想从多个阵列中删除图像。请看我上面链接的全部代码以了解更多信息。我已经更新了我的问题。它仍然没有改变,我只能删除我点击的第一张图片,不能删除我点击下一张的第二张图片。@interdatega通过在此方法中放置断点进行检查,或者使用NSLog在[allImagesArray removeObjectAtIndex:indexPath.row]行后打印allImagesArray的计数;我在[self-deleteMyFiles:trashBin]上设置了一个断点;它不会停止它。@interdatega将brk点和NSLog放入-collectionView:didSelectItemAtIndexPath:delegatemethod@interdatega并检查该委托方法的每次调用的计数是否持续减少