0

我有一个自定义库,可以从相机胶卷中选择多个图像,我将图像保存在NSDocumentDirectory这样的位置:

         for (int i = 0; i < info.count; i++) {
            NSLog(@"%@", [info objectAtIndex:i]);
            NSArray *paths = NSSearchPathForDirectoriesInDomains( NSDocumentDirectory,    NSUserDomainMask ,YES );
            NSString *documentsDir = [paths objectAtIndex:0];
            NSString *savedImagePath = [documentsDir stringByAppendingPathComponent:[NSString stringWithFormat:@"Images%d.png", i]];
            ALAssetRepresentation *rep = [[info objectAtIndex: i] defaultRepresentation];
            UIImage *image = [UIImage imageWithCGImage:[rep fullResolutionImage]];
            //----resize the images
            image = [self imageByScalingAndCroppingForSize:image toSize:CGSizeMake(256,256*image.size.height/image.size.width)];

            NSData *imageData = UIImagePNGRepresentation(image);
            [imageData writeToFile:savedImagePath atomically:YES];

            NSLog(@"saving at:%@",savedImagePath);

        }

我想做的是我想将它加载到缩略图中,UIScrollView然后当点击特定图片时AlertView会弹出一个弹出窗口,询问用户是否要删除它。我设法让它在缩略图视图中加载(我使用HSImageSidebarView),并在AlertVIew用户点击图像时弹出弹出窗口。但是当我按下 delete 时,它​​会在视图中删除,但不会在NSDocumentDirectory.

这就是我删除图像的方式:

- (void)sidebar:(HSImageSidebarView *)sidebar didRemoveImageAtIndex:(NSUInteger)anIndex {
    NSLog(@"Image at index %d removed", anIndex);
    [images removeObjectAtIndex:anIndex];

    NSFileManager *fileManager = [NSFileManager defaultManager];
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentsDirectory = [paths objectAtIndex:0];
    NSString *fullPath = [documentsDirectory stringByAppendingPathComponent:[NSString stringWithFormat:@"Images%d.png", anIndex]];
    [fileManager removeItemAtPath: fullPath error:NULL];
    NSLog(@"image removed");
}
4

1 回答 1

1

在这一行,将 %d 替换为 %lu

NSString *fullPath = [documentsDirectory stringByAppendingPathComponent:[NSString stringWithFormat:@"Images%d.png", anIndex]];
于 2012-06-18T02:58:34.740 回答