【发布时间】:2011-11-30 10:02:24
【问题描述】:
我正在 iPad 上开发此应用程序。
“浏览”按钮的这些代码允许用户查看 iPad 画廊中的照片。
- (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];
}
当一张照片被选中时,它将使用 NSDocumentDirectory 存储到应用程序中。
- (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 中删除。
我该怎么做?
【问题讨论】:
标签: objective-c ios xcode ipad nsdocumentdirectory