【发布时间】:2012-03-13 23:40:35
【问题描述】:
我想从我的 iPhone 应用程序中删除一张图片。 我使用下面的方法,将图像的名称作为参数传递。
问题是图片没有被删除。
- (void)removeImage:(NSString*)fileName {
NSFileManager *fileManager = [NSFileManager defaultManager];
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *fullPath = [documentsDirectory stringByAppendingPathComponent:
[NSString stringWithFormat:@"%@.png", fileName]];
[fileManager removeItemAtPath: fullPath error:NULL];
NSLog(@"image removed: %@", fullPath);
NSString *appFolderPath = [[NSBundle mainBundle] resourcePath];
NSLog(@"Directory Contents:\n%@", [fileManager directoryContentsAtPath: appFolderPath]);
}
最后两行显示了我的应用目录中的内容,我要删除的图像仍然存在。我做错了什么?
【问题讨论】:
标签: ios iphone image uiimage delete-file