我正在尝试从图库中获取图像,而不是在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
正常显示。但是没有任何形象。有我的问题吗?
答案 0 :(得分: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"];
}