ios - 在 iPad 上显示来自 ActionSheet 的 ImagePickerController

标签 ios ipad uiimagepickercontroller uiactionsheet uipopover

背景:在 iPad 上,我有一个按钮,点击该按钮时会显示 UIActionSheet。此操作表有 2 个选项:相机和图库。点击相机后,拉起相机,一切正常。点击图库后,假设会显示一个弹出窗口,其中包含用户的照片。

问题:在 iPad 上,UIActionSheet 的行为类似于弹出框。演示时,无法看到另一个弹出窗口。错误:由于未捕获的异常“NSGenericException”而终止应用程序,原因:“-[UIPopoverController dealloc] 在弹出窗口仍然可见时到达。

我的代码:
设置操作表

- (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];
    }
}

委托(delegate)

- (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; 
}

执行中

- (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];
        }
    }
}

问题:我尝试从 View 中删除操作表,并尝试在执行 pickImage 之前将其关闭。这些都不起作用。如何展示画廊?

最佳答案

您的问题:错误:由于未捕获的异常“NSGenericException”而终止应用程序,原因:“-[UIPopoverController dealloc] 在弹出窗口仍然可见时到达。

在 .h 文件类中创建 UIPopoverController 的对象。确保您的 UIPopoverController 的 @property 是强而不是弱。

检查这个

UIPopoverController: dealloc reached while popover is still visible

UIPopovercontroller dealloc reached while popover is still visible

关于ios - 在 iPad 上显示来自 ActionSheet 的 ImagePickerController,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18188922/

相关文章:

ios - 在我的Xcode项目中找不到<libxml2/tree.h>

ios - 无法控制 iPad 上的扬声器

ios - 如何检查 String 对象是否为链接?

iphone - ipad 应用程序换肤结构/方法?

ios - UIImagePickerController 显示最后一张照片而不是相机输入

ios - imagePickerController 选择照片时出错

ios - 如何在 uiimagepickercontroller 中创建可裁剪的横幅图像?

iphone - 如何突出显示图像中的文字?

ios - Spritekit - Tableview 前面的 Spritenode

ios - 在 IOS 中切片和 reshape MLMultiArray