Possible Duplicate:
UIPopovercontroller dealloc reached while popover is still visible
Im creating a universal app and trying to get an image selected from Camera roll. Works fine on iPhone, iPad wants a pop over, so have done that, now keep getting an error
-[UIPopoverController dealloc] reached while popover is still visible.
Ive researched:
and google, nothing has solved this issue
Stuck now, any advice appreciated
Ive implemented the popover delegate in .h
.m
- (void)logoButtonPressed:(id)sender /////////////iPad requires seperate method ////////////////
{
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) {
LogCmd();
UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
imagePicker.delegate = self;
imagePicker.allowsEditing = YES;
////////
imagePicker.modalPresentationStyle = UIModalPresentationCurrentContext;
////////
[self presentModalViewController:imagePicker animated:YES];
}
else
{
// We are using an iPad
UIImagePickerController *imagePickerController = [[UIImagePickerController alloc] init];
imagePickerController.delegate = self;
UIPopoverController *popoverController=[[UIPopoverController alloc] initWithContentViewController:imagePickerController];
popoverController.delegate=self;
[popoverController presentPopoverFromRect:((UIButton *)sender).bounds inView:sender permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
}
}
I have also now tried this:
.h
@property (strong) UIPopoverController *pop;
.m
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) { ///code added
LogCmd();
UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
imagePicker.delegate = self;
imagePicker.allowsEditing = YES;
[self presentModalViewController:imagePicker animated:YES];
///code added////////////////////////////
}
else {
if (self.pop) {
[self.pop dismissPopoverAnimated:YES];
}
// If usingiPad
UIImagePickerController *imagePickerController = [[UIImagePickerController alloc] init];
UIPopoverController *popoverController=[[UIPopoverController alloc] initWithContentViewController:imagePickerController];
[popoverController presentPopoverFromRect:((UIButton *)sender).bounds inView:sender permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
You instantiate the popover and assign it to a local variable here:
As soon as the method returns, the variable goes out of scope and the object is deallocated since it has no owner anymore.
What you should do is declare a
strongproperty to assign the popover to. You have already done so with yourpopproperty. So now all you need to do is at the time you allocate the popover, assign it to your property. This makes you the owner of the object so it won’t get deallocated.Hope this helps!