【发布时间】:2012-03-26 03:59:50
【问题描述】:
我正在尝试使用 UIImagePickerController 从用户 iPhone / iPad 上的照片中抓取照片。这段代码在 iPhone 上运行得很好,但是当我在 iPad 上运行它时,调试器给了我消息“由于未捕获的异常 'NSGenericException' 导致应用程序终止,原因:'-[UIPopoverController dealloc] 在弹出窗口仍然可见时达到。”。我对 Objective-C 很陌生,所以我不确定是什么原因造成的,我没有释放任何东西,我打开了 ARC。这是我的代码: 视图控制器.m
#import "PhotoViewController.h"
@implementation PhotoViewController
@synthesize grabButton;
@synthesize image;
@synthesize imgPicker;
- (IBAction)grabImage {
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad) {
UIPopoverController *popover = [[UIPopoverController alloc] initWithContentViewController:imgPicker];
[popover presentPopoverFromRect:self.image.bounds inView:self.image permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
} else {
[self presentModalViewController:imgPicker animated:YES];
}
}
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)img editingInfo:(NSDictionary *)editInfo {
image.image = img;
[[picker parentViewController] dismissModalViewControllerAnimated:YES];
}
- (void)viewDidLoad
{
self.imgPicker = [[UIImagePickerController alloc] init];
self.imgPicker.allowsImageEditing = YES;
self.imgPicker.delegate = self;
self.imgPicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
}
【问题讨论】:
-
发帖前我看过了,可惜没用。
标签: objective-c ios uipopovercontroller