我的应用程序有一个带有这些代码的“浏览”按钮,允许用户浏览 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 中删除。
是否有可能做到这一点?如果是,介意告诉我怎么做并分享一些示例代码吗?我很迷茫,因为我对编程还是很陌生。