我想在iPad上使用相机,我必须在iPad上使用UIPopoverController。无论UIPopoverController声明强大,我都会收到以下错误!
*** Terminating app due to uncaught exception 'NSGenericException', reason: '-[UIPopoverController dealloc] reached while popover is still visible.'
以下是我的代码。谁能告诉我我做错了什么?我已经完成了关于SO的大部分相关问题,但是大多数人都说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
答案 0 :(得分:1)
在这种情况下,PopoverController拥有ImagePicker所以问题是(可能)你正在解雇ImagePicker而不是容器PopoverController。
你打电话的地方
[picker dismissModalViewControllerAnimated:YES];
使用
[self.popoverController dismissPopoverAnimated:YES];
Theres无需明确解除ImagePicker
答案 1 :(得分:0)
尝试添加@property(nonatomic, strong) UIImagePickerController *imagePickerController;
合成它@synthesize imagePickerController;
并更改imagePickerController
方法captureImageFromCamera
,如下所示:
imagePickerController = [[UIImagePickerController alloc] init];
答案 2 :(得分:0)
我无法解决我的问题,但this也像iOS 5上的魅力一样。感谢http://www.techotopia.com!