Ipad照片选择器

时间:2012-08-03 00:47:30

标签: ios xcode ipad

我想让IPAD从相册中选择一张照片

            pickerController = [ [ UIImagePickerController alloc ] init ] ;
            pickerController.delegate   = self ;
            pickerController.editing    = NO ;
            pickerController.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;

            [ self presentViewController : pickerController animated : YES completion : nil ] ;

当我在iPad上使用它时,应用程序会一直崩溃,但在iPhone上运行正常。

1 个答案:

答案 0 :(得分:6)

这个人也得到了我。在iPad上,如果指定源类型UIImagePickerControllerSourceTypePhotoLibraryUIImagePickerControllerSourceTypeSavedPhotoAlbum,则需要使用弹出控制器显示图像选择器控制器。如果你尝试以模态方式呈现它,就像你正在做的那样,你会得到一个例外。

不是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];
}