加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

objective-c – XCode – 显示/删除NSDocumentDirectory中的文件

发布时间:2020-12-14 17:20:50 所属栏目:百科 来源:网络整理
导读:我的应用程序有一个带有这些代码的“浏览”按钮,允许用户浏览iPad的照片库,选择照片并使用NSDocumentDirectory将其存储到应用程序中. - (IBAction) BrowsePhoto:(id)sender{UIImagePickerController *imagePickerController = [[UIImagePickerController all
我的应用程序有一个带有这些代码的“浏览”按钮,允许用户浏览iPad的照片库,选择照片并使用NSDocumentDirectory将其存储到应用程序中.

- (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中删除.

是否有可能做到这一点?如果是,请记住如何操作并分享一些示例代码?我很失落,因为我还是很喜欢编程.

解决方法

您需要处理文件的所有内容都在名为NSFileManager的系统类中实现.

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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读