我正在尝试让 IPAD 从相册中选择一张照片
pickerController = [ [ UIImagePickerController alloc ] init ] ;
pickerController.delegate = self ;
pickerController.editing = NO ;
pickerController.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;
[ self presentViewController : pickerController animated : YES completion : nil ] ;
当我在 iPad 上使用时,该应用程序不断崩溃,但在 iPhone 上运行良好。
最佳答案
这个以前也有过我。在 iPad 上,如果您指定源类型 UIImagePickerControllerSourceTypePhotoLibrary
或 UIImagePickerControllerSourceTypeSavedPhotoAlbum
您需要使用弹出框 Controller 呈现图像选择器 Controller 。如果你尝试以模态方式呈现它,就像你正在做的那样,你会得到一个异常(exception)。
不是 100% 需要,但使用测试查看可用的源类型也是一个好主意。
[UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary]
源类型有:
UIImagePickerControllerSourceTypePhotoLibrary
UIImagePickerControllerSourceTypeSavedPhotosAlbum
UIImagePickerControllerSourceTypeCamera
这就是我解决这个问题以测试它是否是 iPad 的方法。
if( UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad){
UIPopoverController* popOverController = [[UIPopoverController alloc] initWithContentViewController:imagePickerController];
[popOverController presentPopoverFromRect:selectVideoToViewButton.bounds inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
}else {
[self presentModalViewController:self.imagePickerController animated:YES];
}
关于ios - Ipad 照片选择器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11787828/