Henry F
Henry F

Reputation: 4980

iOS: UIPopoverController Error

I'm trying to make my application grab a photo from the user's Photo library using UIImagePickerController and display it in the app. My code works great for the iPhone, but I need to use UIPopoverController for the iPad. I'm still very new to programming in general, so I'm having a really difficult time trying to figure out how to do this. While testing it out, I ran into a strange error. The debugger says "Terminating app due to uncaught exception 'NSGenericException', reason: '-[UIPopoverController dealloc] reached while popover is still visible." but I don't dealloc anything, I have ARC turned on. Here is my code:

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.

}

Any help is much appreciated! Thank you!

Upvotes: 0

Views: 620

Answers (1)

borrrden
borrrden

Reputation: 33423

Ray Wenderlich has a nice tutorial on UIPopoverControllers here: http://www.raywenderlich.com/1056/ipad-for-iphone-developers-101-uipopovercontroller-tutorial

Upvotes: 1

Related Questions