0

我使用以下代码从 iphone 的相册中获取照片,但显示错误“UIImagePickerController must be present via UIPopoverController”

- (void)showImagePicker:(UIImagePickerControllerSourceType)sourceType
{

    if ([UIImagePickerController isSourceTypeAvailable:sourceType])
    {
        [self setupImagePicker:sourceType];

        [self presentModalViewController:imagePickerController animated:YES];

    }
}


- (void)setupImagePicker:(UIImagePickerControllerSourceType)sourceType
{
    imagePickerController.sourceType = sourceType;

    if (sourceType == UIImagePickerControllerSourceTypeCamera)
    {
        // user wants to use the camera interface
        //
        imagePickerController.showsCameraControls = NO;

        if (imagePickerController.cameraOverlayView != self.view)
        {
            // setup our custom overlay view for the camera
            //
            // ensure that our custom view's frame fits within the parent frame
            CGRect overlayViewFrame = imagePickerController.cameraOverlayView.frame;
            CGRect newFrame = CGRectMake(0.0,
                                         CGRectGetHeight(overlayViewFrame) -
                                         self.view.frame.size.height - 9.0,
                                         CGRectGetWidth(overlayViewFrame),
                                         self.view.frame.size.height + 9.0);
            self.view.frame = newFrame;
            imagePickerController.cameraOverlayView = self.view;
        }
    }
}



-(IBAction)getPhoto:(id)sender {
        imagePickerController = [[UIImagePickerController alloc] init];
        [self showImagePicker:UIImagePickerControllerSourceTypePhotoLibrary];
}

任何人都可以更改我的代码以在 iPad 上工作。提前致谢。

4

1 回答 1

1

-(IBAction)Click_event {

UIImagePickerController *imagePickerController_=[[UIImagePickerController alloc] init];
    UIPopoverController *popover_=[[UIPopoverController alloc] initWithContentViewController:imagePickerController_];
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary]) {
        imagePickerController_.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
[popover_ presentPopoverFromRect:CGRectMake(400, 400, 0, 0) inView:self.Mybutton
                permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];


   }

 }
于 2012-10-04T12:28:47.837 回答