objective-c - iOS:UIPopoverController 错误

标签 objective-c ios ipad uipopovercontroller

我正在尝试让我的应用程序使用 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/

相关文章:

ios - 防止转义 URL 中的括号

iOS 模拟器在 Xcode 10 上崩溃

ios - 我可以为 System UIFont 设置 ascender 或 descender 吗?

iphone - UISplitViewController 和复杂的 View 层次结构

iphone - 在文本字段中模仿 Twitter/G+ 标记功能

ios - 在 iOS 8.2 上更改 UIBarButtonItem 的垂直位置

尝试加载时 iPhone 应用启动画面崩溃

ios - 如何确保我的详细信息 View Controller 始终嵌入到 UINavigationController 中?

iphone - 通过网站分发 iPad 应用程序(.ipa 格式文件)

objective-c - 是否有任何好的开源 Mac 应用程序模板