我试图使我的应用程序使用UIImagePickerController从用户的图片库中抓取一张照片,并将其显示在应用程序中。我的代码在iPhone上效果很好,但是我需要在iPad上使用UIPopoverController。总体而言,我对编程还是很陌生,所以我很难找到解决方法。在测试时,我遇到了一个奇怪的错误。调试器说:“由于未捕获的异常'NSGenericException',正在终止应用程序,原因:'-[UIPopoverController dealloc]在弹出窗口仍然可见的情况下到达。”但我没有取消任何分配,我已打开ARC。这是我的代码:
ViewController.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.
}
任何帮助深表感谢!谢谢!
最佳答案
Ray Wenderlich在这里有关于UIPopoverControllers的不错的教程:http://www.raywenderlich.com/1056/ipad-for-iphone-developers-101-uipopovercontroller-tutorial
关于objective-c - iOS:UIPopoverController错误,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/9865635/