gpt4 book ai didi

ios - UIImageView Picker 在 ipad 中给出异常

转载 作者:行者123 更新时间:2023-11-28 22:26:54 24 4
gpt4 key购买 nike

我正在使用 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com