0

I did convert an image with:

UIImage *image = [UIImage imageNamed:"myImg.png"];
NSData *myData = UIImagePNGRepresentation(image);

//i had to convert it because I am sending it to the server

After receiving the NSData on the server side, I want now to display the image in a uiimageview

I did the following:

UIImage *convImg = [UIImage imageWithData:myData];
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"" message:nil delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];

    UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(160.5, 27, 40, 40)];

    UIImage *bkgImg = [[UIImage alloc] initWithData:myData];
    [imageView setImage:bkgImg];

    [alert addSubview:imageView];

    [alert show];

there is no image displayed. What am I doing wrong?

just ME
  • 1,817
  • 6
  • 32
  • 53
  • I understand you are converting "image" to data to send it the server, however why are you not using "image" as the image for "imageView"? Also, what is the purpose of "convImg", as you don't use it in the code above? – Nick Jun 06 '14 at 08:19
  • If you are using this in iOS7, then iOS7 does not allow subviews to be to UIAlertView's (http://stackoverflow.com/questions/19683207/uialertview-insert-image) – Nick Jun 06 '14 at 08:25

2 Answers2

0

On ios7 , I manage to solve the issue by changing:

[alert addSubview imageView];

with

[alert setValue:imageView forKey@"accessoryView"];
just ME
  • 1,817
  • 6
  • 32
  • 53
0

You are not loading the image in the first place as there is a typo (you are missing the @ character). Are you not getting a compiler error / warning?

Try replacing this line:

UIImage *image = [UIImage imageNamed:"myImg.png"];


With this:

UIImage *image = [UIImage imageNamed:@"myImg.png"];