简体   繁体   English

对于iPad开发人员:如何在iPad的UIImageView中查看从照片库的弹出菜单中选择的图像

[英]For iPad Developers: How to view an image selected from photo library’s popover in a UIImageView, iPad

I am working on an application for iPad, it is working fine until i reached this point: 我正在为iPad开发应用程序,在达到这一点之前,它可以正常工作:

The app shows the popover for the photo library, but when I choose the photo, the popover doesn't hide, and I also want it to view the selected image in a UIImageView, however i do not know how. 该应用程序显示照片库的弹出窗口,但是当我选择照片时,该弹出窗口不会隐藏,并且我还希望它在UIImageView中查看选定的图像,但是我不知道如何。

I am sure there is something wrong in the didFinishpickingMediaWithInfo function. 我确定didFinishpickingMediaWithInfo函数有问题。 here is the function's code: 这是函数的代码:

 -(void) imagePickerController:(UIImagePickerController *)picker didFinishpickingMediaWithInfo:(NSDictionary *)info{
    //bgImage is a UIImageView
bgImage = [info objectForKey:@"UIImagePickerControllerOriginalImage"];

// Dismiss UIImagePickerController and release it [picker dismissModalViewControllerAnimated:YES]; 
[picker.view removeFromSuperview]; 
[picker release];
}

My first question is: What am I supposed to add to this function for viewing the selected photo in the UIImageView? 我的第一个问题是:我应该在此功能中添加什么以在UIImageView中查看所选照片? (When I click on the photo from the photo library in the simulator, neither the photo library hide nor the image is viewed in the specified UIImageView) (当我从模拟器中的照片库中单击照片时,既不会隐藏照片库,也不会在指定的UIImageView中查看图像)

2- I have read that I should've used UIImage instead of UIImageView.. Is this true? 2-我读过我应该使用UIImage而不是UIImageView。 If yes, what about the interface builder? 如果是,那么界面生成器如何? There is nothing called UIImage? 有没有所谓的UIImage?

To close the image picker, use: 要关闭图像选择器,请使用:

[[picker parentViewController] dismissModalViewControllerAnimated:YES];

What you get from 你从中得到什么

bgImage = [info objectForKey:@"UIImagePickerControllerOriginalImage"];

is not an UIImageView, it's a UIImage. 不是UIImageView,而是UIImage。 To get it displayed, you need to have a UIImageView in your UI somewhere, and set the view's image with what you just got from the picker: 为了显示它,您需要在UI的某个地方有一个UIImageView,并使用您从选择器中获得的图像来设置视图的图像:

imageView.image = bgImage

Hope this helps 希望这可以帮助

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM