0

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

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

picker.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;

[self presentModalViewController:picker animated:YES];
4

2 回答 2

2

在 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];


    }

}
于 2013-09-09T07:49:49.240 回答
0

在 iPad 中,您必须像这样使用它:

UIPopoverController *popover = [[UIPopoverController alloc] initWithContentViewController: picker];

[popover presentPopoverFromBarButtonItem: item
                permittedArrowDirections: UIPopoverArrowDirectionAny
                                animated: YES];

或者

[popover presentPopoverFromRect: CGRectMake(0, 0, 100, 100)
                         inView: self.view
       permittedArrowDirections: UIPopoverArrowDirectionAny
                       animated: YES];
于 2013-09-09T07:51:06.517 回答