Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/27.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
iOS-选择器控制器未打开照片库_Ios_Objective C_Uiimagepickercontroller_Uiactionsheet - Fatal编程技术网

iOS-选择器控制器未打开照片库

iOS-选择器控制器未打开照片库,ios,objective-c,uiimagepickercontroller,uiactionsheet,Ios,Objective C,Uiimagepickercontroller,Uiactionsheet,在我的应用程序中,我使用UIActionSheet和UIImagePickerController。操作表打开选项(如选择照片、选择视频),图像选择器控制器打开库。该系统适用于iPhone设备测试,但对于iPad,操作表可以正常工作,而Picker控制器不能 我已经为iOS10、照相机和照片库设置了必需的权限。这不可能是问题所在 我选择照片的代码: - (void)selectPhoto { self.imagePickerController.delegate = self;

在我的应用程序中,我使用UIActionSheet和UIImagePickerController。操作表打开选项(如选择照片、选择视频),图像选择器控制器打开库。该系统适用于iPhone设备测试,但对于iPad,操作表可以正常工作,而Picker控制器不能

我已经为iOS10、照相机和照片库设置了必需的权限。这不可能是问题所在

我选择照片的代码:

- (void)selectPhoto {

    self.imagePickerController.delegate = self;
    self.imagePickerController.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
    self.imagePickerController.mediaTypes = [NSArray arrayWithObjects:(NSString *)kUTTypeImage, nil];
    [self presentViewController:self.imagePickerController animated:YES completion:nil];
}
也编写了所需的委托方法。正如我所提到的,iPhone的每一项功能都应该发挥作用

当我尝试首先打开照片库时,我收到以下警告消息:

[警告]正在进行 要求设置其不透明度的动画。这将导致效果出现 直到不透明度恢复为1为止

没有损坏,应用程序仍在运行(未冻结)。但是,如果我尝试打开照片库,这次我会得到:

警告:试图在上显示 已显示的(空)

然后,问题可能是爆米花问题,但我找不到答案。 谢谢大家!

编辑:我的行动表委托方法:

-(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {

    [actionSheet dismissWithClickedButtonIndex:buttonIndex animated:YES];
    switch (buttonIndex) {
        case 0:
            [self selectPhoto];
            break;
        case 1:
            [self selectVideo];
            break;
        default:
            break;
    }
}
编辑2:我发现:

在iPad上,您必须使用popover作为浏览器界面 在initWithContentViewController:中描述,并演示和 取消UIPopoverController类引用中的Popover。如果 iPad,您尝试以模式显示浏览器界面 (全屏),系统会引发异常


UIPopoverController现在已弃用。因此,我应该用另一种方式。如果有人能在这方面帮助我,我将非常高兴。

有一个列表,列出了所有Cocoa密钥,您可以在Info.plist文件中指定:


iOS先前已经要求获得访问麦克风、摄像头和媒体库的权限(iOS6、iOS7),但由于iOS10,如果您不提供请求权限的说明,应用程序将崩溃。

在iPad上,您无法在已经在屏幕上显示的UIActionSheet popover上显示UIImagePickerController popover

替换

- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex

它必须起作用


并删除
[操作表使用ClickedButtonIndex解散:buttonIndex动画:是]
,只要你点击一个按钮,
UIActionSheet
就会自动关闭。

要在iPhone和iPad上显示图像选择器,你需要将其显示为一个弹出框

因此,显示选择器的实现将更改为

self.imagePickerController.delegate = self;
self.imagePickerController.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
self.imagePickerController.mediaTypes = [NSArray arrayWithObjects:(NSString *)kUTTypeImage, nil];
self.imagePickerController.modalPresentationStyle = UIModalPresentationPopover; //This is needed
self.imagePickerController.sourceView = self.view; //This is needed
[self presentViewController:self.imagePickerController animated:YES completion:nil];

在出示选取器之前,请确保您的操作表已被驳回。

对于iPad,请使用代码打开UIImagePicker

 [[NSOperationQueue mainQueue] addOperationWithBlock:^{

                [self presentViewController:picker animated:NO completion:nil];
            }];

在演示
UIImagePickerController
之前,您是否已退出
UIActionSheetController
?我没有,但现在我退出了。仍然相同。请显示用于解除警报的附加代码。您需要确保在完成时显示图像选择器。否则就不行了。
 [[NSOperationQueue mainQueue] addOperationWithBlock:^{

                [self presentViewController:picker animated:NO completion:nil];
            }];