ipad - ARC 环境下 iPad 上的 UIPopoverController 和 UIImagePickerController

标签 ipad crash uiimagepickercontroller uipopovercontroller

我正在尝试在 iPad 上使用相机,为此我必须在 iPad 上使用 UIPopoverController。无论 UIPopoverController 声明为强,我都收到以下错误!

*** Terminating app due to uncaught exception 'NSGenericException', reason: '-[UIPopoverController dealloc] reached while popover is still visible.'

以下是我的代码。谁能告诉我我做错了什么吗?我已经解决了大多数相关问题,但大多数人都说声明 UIPopoverController 强大,我已经在这样做了!

#import "ImagePickerController.h"

@interface ImagePickerController()
    @property(nonatomic, strong) UIPopoverController *popoverController;
@end

@implementation ImagePickerController

@synthesize imageName;
@synthesize popoverController;

- (void)didReceiveMemoryWarning
{
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
}

- (void)viewDidUnload
{
    [super viewDidUnload];
}

#pragma mark - UIImagePickerController Delegate

-(void) captureImageFromCamera:(UIViewController*)view
{

        UIImagePickerController *imagePickerController = [[UIImagePickerController alloc] init];
        imagePickerController.delegate = self;
        self.popoverController = [[UIPopoverController alloc] initWithContentViewController:imagePickerController];
        self.popoverController.delegate = self;
        [self.popoverController presentPopoverFromRect:view.view.bounds inView:view.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
}

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info 
{
    [picker dismissModalViewControllerAnimated:YES];
}

- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker 
{
    [picker dismissModalViewControllerAnimated:YES];
}

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)image editingInfo:(NSDictionary *)editingInfo
{
[picker dismissModalViewControllerAnimated:YES];
}

#pragma mark - UIPopoverController Delegate

- (void)popoverControllerDidDismissPopover:(UIPopoverController *)popoverController
{

}

- (BOOL)popoverControllerShouldDismissPopover:(UIPopoverController *)popoverController
{
    return YES;
}

@end

最佳答案

在这种情况下,PopoverController 拥有 ImagePicker,因此问题(可能)是您正在忽略 ImagePicker 而不是容器 PopoverController。

你打电话的地方

[选择器dismissModalViewControllerAnimated:YES];

使用

[self.popoverController DismissPopoverAnimated:YES];

无需显式关闭 ImagePicker

关于ipad - ARC 环境下 iPad 上的 UIPopoverController 和 UIImagePickerController,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11455141/

相关文章:

iPhone:获取相机预览

ios - UICollectionView - 在横向模式下重新设计

iphone - UIPinchGestureRecognizer 没有被调用

iphone - UISegmentedControl 非常奇怪的问题

android 应用程序不断崩溃 audioEffect 错误代码 -1

swift - Ios swift相机图像选择器旋转问题

iphone - Facebook 页面就像 iOS 中一样

c# - 使用C#构建的Android应用在真实设备上崩溃,但可在模拟器上运行

iphone - 我还能从这份崩溃报告中获得哪些其他信息?

ios - StackView 内部的 CollectionView