0

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

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

以下是我的代码。谁能告诉我我做错了什么?我已经解决了关于 SO 的大多数相关问题,但其中大多数都说声明 UIPopoverController strong 我已经在做!

#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
4

3 回答 3

1

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

你打电话的地方

[picker dismissModalViewControllerAnimated:YES];

采用

[self.popoverController dismissPopoverAnimated:YES];

无需显式关闭 ImagePicker

于 2012-07-12T15:59:24.470 回答
0

尝试添加@property(nonatomic, strong) UIImagePickerController *imagePickerController;

合成它 @synthesize imagePickerController;

并像这样更改imagePickerController方法captureImageFromCamera

imagePickerController = [[UIImagePickerController alloc] init];
于 2012-07-12T15:34:15.030 回答
0

我无法解决我的问题,但这iOS 5 上也很有效。感谢http://www.techotopia.com

于 2012-07-12T15:55:30.907 回答