0

次のコードを使用して iPhone のアルバムから写真を取得しましたが、「UIImagePickerController は 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 に答える