我正在尝试让我的应用程序使用 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 在此处提供了有关 UIPopoverController 的精彩教程:http://www.raywenderlich.com/1056/ipad-for-iphone-developers-101-uipopovercontroller-tutorial
关于objective-c - iOS:UIPopoverController 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9865635/