I am trying to use camera on iPad and I have to use UIPopoverController on iPad for this. I have been getting following error no matter UIPopoverController declared strong!
*** Terminating app due to uncaught exception 'NSGenericException', reason: '-[UIPopoverController dealloc] reached while popover is still visible.'
Following is my code. Could anyone please tell me what am I doing wrong? I have went through most of related questions on SO but most of them says declare UIPopoverController strong that I am already doing!
#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
I couldn’t resolve my issue but this worked like a charm on iOS 5 as well. Thanks to http://www.techotopia.com!