首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >XCode -从NSDocumentDirectory中显示/删除文件

XCode -从NSDocumentDirectory中显示/删除文件
EN

Stack Overflow用户
提问于 2011-10-04 10:08:20
回答 1查看 2.8K关注 0票数 4

我的应用程序有一个带有这些代码的“浏览”按钮,允许用户浏览iPad的相册,选择一张照片,并使用NSDocumentDirectory将其存储到应用程序中。

代码语言:javascript
复制
- (IBAction) BrowsePhoto:(id)sender
{
UIImagePickerController *imagePickerController = [[UIImagePickerController alloc] init];
imagePickerController.delegate = self;
imagePickerController.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
UIPopoverController *popover = [[UIPopoverController alloc] initWithContentViewController:imagePickerController];
[popover setPopoverContentSize:CGSizeMake(320,320)];
[popover presentPopoverFromRect:CGRectMake(200,200,-100,-100) inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
self.popoverController = popover;
[imagePickerController  release];
}

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)selectedImage editingInfo:(NSDictionary *)editingInfo 
{
[self.popoverController dismissPopoverAnimated:YES];
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDir = [paths objectAtIndex:0];
NSString *savedImagePath = [documentsDir stringByAppendingPathComponent:@"SavedImage.png"];
UIImage *image = imageView.image;
NSData *imageData = UIImagePNGRepresentation(image);
[imageData writeToFile:savedImagePath atomically:NO];
}

现在我想包括一个“显示”按钮,它在一个新的视图中显示来自NSDocumentDirectory的所有照片。我正在考虑在缩略图中显示它,而且当点击一个图像时,它会弹出一个窗口,要求用户确认他/她是否要删除选定的照片。如果是,该照片将从NSDocumentDirectory中删除。

有可能做到这一点吗?如果是,介意告诉我怎么做并分享一些示例代码吗?我完全迷失了方向,因为我对编程还很陌生。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2011-11-01 18:50:27

您需要对文件执行的所有操作都在名为NSFileManager的系统类中实现。

这并不复杂。尝试阅读文档并搜索一些示例。它们有很多,例如http://www.theappcodeblog.com/2011/04/04/nsfilemanager-tutorial-create-read-and-delete-a-file/

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/7642610

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档