Note that there are some explanatory texts on larger screens.

plurals
  1. PODisplaying ImagePickerController From ActionSheet on iPad
    primarykey
    data
    text
    <p><strong>Background:</strong> On iPad, I have a button which when tapped, showed a <code>UIActionSheet</code>. This action sheet has 2 options, camera and gallery. Camera when tapped, pulled up a camera and everything works fine. Gallery when tapped, suppose to show a popover with user's photos in it. </p> <p><strong>Problem:</strong> On iPad, <code>UIActionSheet</code> acts like a popover. Which when presenting, another popover cannot come into view. Error:<code>Terminating app due to uncaught exception 'NSGenericException', reason: '-[UIPopoverController dealloc] reached while popover is still visible.</code></p> <p><strong>My code:</strong><br> Setting Action Sheet </p> <pre><code>- (void)imageButtonTapped:(UIButton *)sender { if (_commentObject.image){ _actionSheet = [[UIActionSheet alloc] initWithTitle:@"Action" delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:@"Remove" otherButtonTitles:nil]; _actionSheet.tag = ACTION_IMAGE_REVIEW_TAG; }else{ _actionSheet = [[UIActionSheet alloc] initWithTitle:@"Image Source" delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:nil otherButtonTitles:@"Camera", @"Gallery", nil]; _actionSheet.tag = ACTION_IMAGE_SOURCE_TAG; } if (_isPad) { [_actionSheet showFromRect:_imageButton.frame inView:_scrollViewContent animated:YES]; }else{ [_actionSheet showInView:self.view]; } } </code></pre> <p>Delegate</p> <pre><code>- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex { switch (actionSheet.tag) { case ACTION_IMAGE_SOURCE_TAG: switch (buttonIndex) { case 0: [self pickImage:YES]; break; case 1: [self pickImage:NO]; break; default: break; } break; } </code></pre> <p>Executing</p> <pre><code>- (void)pickImage:(BOOL)fromCamera { if (fromCamera) { if([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]){ UIImagePickerController* cameraPickerController = [[UIImagePickerController alloc] init]; cameraPickerController.sourceType = UIImagePickerControllerSourceTypeCamera; cameraPickerController.delegate = self; [self presentViewController:cameraPickerController animated:YES completion:nil]; }else{ UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Camera Unavailable" message:@"Your Device does not support Cameras" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles: nil]; [alert show]; } }else{ UIImagePickerController *galleryPickerController = [[UIImagePickerController alloc] init]; galleryPickerController.sourceType = UIImagePickerControllerSourceTypePhotoLibrary; galleryPickerController.delegate = self; if (_isPad) { if ([_actionSheet isVisible]) { [_actionSheet removeFromSuperview]; UIPopoverController *imagePickerPopover = [[UIPopoverController alloc] initWithContentViewController:galleryPickerController]; [imagePickerPopover presentPopoverFromRect:_imageButton.frame inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES]; } }else{ [self presentViewController:galleryPickerController animated:YES completion:nil]; } } } </code></pre> <p><strong>Question:</strong> I tried removing the action sheet from view, and tried dismissing it before executing <code>pickImage</code>. None of that works. How do I present the gallery?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload