-1

I want to delete pictures using the CollectionView that is getting the photo from the directory folders since I have made sub directory to store the images.

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

    NSLog(@"ray:%d", [Trash count]);
    NSString *trashBin = [Trash objectAtIndex:indexPath.row];
    NSLog(@"k%@l",trashBin);


}

This is my code for delete but I have to add the file delete code which I don't know.

4

1 回答 1

1

我相信下面是您正在寻找的。

NSError *error;
NSString *myFileName;
// this is global variable


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

    NSLog(@"ray:%d", [Trash count]);
    NSString *myFileName = [Trash objectAtIndex:indexPath.row];

    NSLog(@"k%@l",myFileName);
    [self deleteMyFiles];



}

-(void) deleteMyFiles {
    NSFileManager *fileMgr = [NSFileManager defaultManager];

    // Point to Document directory
    NSString *documentsDirectory = [NSHomeDirectory() 
         stringByAppendingPathComponent:@"Documents"];

    NSString *filePath2 = [documentsDirectory 
                             stringByAppendingPathComponent:myFileName];

    if ([fileMgr removeItemAtPath:filePath2 error:&error] != YES)
      NSLog(@"Unable to delete file: %@", [error localizedDescription]);
}

欲了解更多详情,请访问,

http://iosdevelopertips.com/data-file-management/iphone-file-system-creating-renaming-and-deleting-files.html

此链接包含文件中要执行的所有操作示例。


你得到这个是因为你没有设置错误。

NSError *error;之前添加NSError *myFileName;

NSError *error;
NSString *myFileName;
// this is global variable
于 2013-08-27T11:49:32.193 回答