0

我正在尝试从图库中获取图像,然后将其显示在 UIImageView 中。我的问题是显示此图像。我的代码:

- (void)getMediaFromSource:(UIImagePickerControllerSourceType)sourceType {

     UIImagePickerController *imagePickerController = [[UIImagePickerController alloc] init];
     imagePickerController.delegate = self;
imagePickerController.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;

     self.popController = [[UIPopoverController alloc] initWithContentViewController:imagePickerController];
     self.popController.delegate = self;
     [self.popController presentPopoverFromRect:[fromGalaryButton frame] inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
}

-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
     [self.popController dismissPopoverAnimated:YES];
     self.image = [info objectForKey:UIImagePickerControllerEditedImage];
     [self updateDisplay];
 }

 -(void)updateDisplay {
     self.imageView.image = self.image;
     self.imageView.hidden = NO;
     [self.imageView reloadInputViews];
}

self.imageView的显示正常。但是里面没有任何图像。有我的问题吗?

4

1 回答 1

2

如果您只是从图库中挑选图像,那么didFinishPickingMediaWithInfo方法中的代码行应该是:

self.image = [info objectForKey:UIImagePickerControllerOriginalImage];

您也可以从方法中更新 imageView,如下所示:

self.imageView.image = [info objectForKey:UIImagePickerControllerOriginalImage];

我就是这样做的:

- (void)viewDidLoad {
  [super viewDidLoad];
  picker = [[UIImagePickerController alloc] init];
  picker.delegate = self;
  imagePickerPopover = [[UIPopoverController alloc] initWithContentViewController:picker];

}

- (IBAction)getPhoto:(id)sender {

if(sender == choosePhotoButton) {
   picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
   [imagePickerPopover presentPopoverFromBarButtonItem:choosePhotoButton permittedArrowDirections:UIPopoverArrowDirectionUp animated:YES];
}
}

    - (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
        [imagePickerPopover dismissPopoverAnimated:YES];
        imageViewer.image = [info objectForKey:@"UIImagePickerControllerOriginalImage"];

    }
于 2012-07-31T19:05:40.247 回答