我試圖使用UIImagePickerController從iPhone/iPad上的用戶照片抓取照片。這段代碼適用於iPhone,但是當我在iPad上運行它時,調試器給我提示消息「由於未捕獲的異常'NSGenericException'導致終止應用程序,原因:' - [UIPopoverController dealloc]在popover仍然可見時到達」。我對Objective-C非常陌生,所以我不確定導致這種情況的原因,我不會釋放任何東西,並且我已經打開了ARC。這裏是我的代碼: ViewController.mUIPopoverController奇怪的錯誤
#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.
}
可能的欺騙:HTTP ://stackoverflow.com/questions/8895071/uipopovercontroller-dealloc-reached-while-popover-is-still-visible – CodaFi 2012-03-26 04:10:31
我在發帖之前看了一下,很不幸沒有幫助。 – 2012-03-26 04:14:39