0
votes

I am working on an application for iPad, it is working fine until i reached this point:

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 knowhow.

I am sure there is something wrong in the didFinishpickingMediaWithInfo function. 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?

2- I have read that I should've used UIImage instead of UIImageView.. Is this true? If yes, what about the interface builder? there is nothing called UIImage ?

Many thanks in advance.. :-) Regards, Rawan

2
yes it should be UIImage and yes there is no UIImage in IB but use UIImageView in IB and call setImage to it and pass that UIImage object function in it.saadnib
Thank you Saadnib, Ok then, what about the first question? Is this code enough for viewing the photo n UIImage, cause I did try what you said and it didn't work.. Thanks alot, really appreciated!Rawan Wabil

2 Answers

0
votes

First add an UIImageView in IB the create IBOutlet for that UIImageView in your .h file then connect UIImageView to this IBOutlet in IB. Then in your didFinishpickingMediaWithInfo get the selectedImage in an UIImage instance and then call setImage to that IBOutlet you created for UIImageView and pass the selected image instance to setImage.

0
votes
-(void) imagePickerController:(UIImagePickerController *)picker didFinishpickingMediaWithInfo:(NSDictionary *)info{
    // TempImage is a UIImage instance
    TempImg = [info objectForKey:@"UIImagePickerControllerOriginalImage"];
    //bgImage is a UIImageView instance and it's connected in the IB
    [bgImage setImage:TempImg];
    // Dismiss UIImagePickerController and release it
    [picker dismissModalViewControllerAnimated:YES];
    [picker.view removeFromSuperview];
    [picker release];

}

I am really sorry for bothering, and really appreciating your given time.. :-)