ios - UIImageView Picker 在 ipad 中给出异常

标签 ios ipad uiimagepickercontroller

我正在使用 UIImagePicker 从库中加载图像,但它给出了异常 说在 ipad 上使用 popover。我也试过了,但不知道如何解决这个问题。

   UIImagePickerController * picker = [[UIImagePickerController alloc] init];
picker.delegate = self;

picker.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;

[self presentModalViewController:picker animated:YES];

最佳答案

要在 ipad 或 iphone 中打开 UIImagePicker,请使用以下代码:-

#define isiPhone (UI_USER_INTERFACE_IDIOM() == 0)?TRUE:FALSE

 UIImagePickerController *pckrImage = [[UIImagePickerController alloc] init];
    pckrImage.delegate = self;
if (isiPhone) {
                if ([UIImagePickerController isSourceTypeAvailable: UIImagePickerControllerSourceTypePhotoLibrary])
                {
                    pckrImage.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
                    [self presentModalViewController:pckrImage animated:YES];
                }
                else {

                }
            }
            else
            {
                popover = [[UIPopoverController alloc]initWithContentViewController:pckrImage];
                [popover presentPopoverFromRect:CGRectMake(450.0f, 825.0f, 10.0f, 10.0f) inView:self.view permittedArrowDirections:UIPopoverArrowDirectionDown animated:YES];


            }

对于在选择 UIImaegPicker 时解雇:-

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
 if(isiPhone)
    {
        [self dismissViewControllerAnimated:YES completion:^{

        }];
    }
    else
    {
        [popover dismissPopoverAnimated:YES];


    }

}

关于ios - UIImageView Picker 在 ipad 中给出异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18693482/

相关文章:

ios - 带有外部库的 cocoaPods pod 文件

ios - 如何使用 PromiseKit 处理仅 header 响应?

ios - 在 iPad 上,当浏览器为 'closed' 时,如何使网页上的嵌入声音停止播放?

ios - 异步使用 NSXMLParser 的问题

ios - 有谁知道手机屏幕顶部与相机图像预览开始之间的像素距离?

ios - 自适应精度算法/方程

objective-c - iOS:使用 NSXMLParser 从 HTTP 解析 xml

ipad - 在 iPad 中居中一个 uipopover

ios - iOS 中的自定义相机,例如 Snapchat

ios - 如何检测隐私权限更改(例如相机访问)