我确实将图片转换为:
UIImage *image = [UIImage imageNamed:"myImg.png"];
NSData *myData = UIImagePNGRepresentation(image);
//我必须转换它,因为我将它发送到服务器
在服务器端收到NSData后,我现在想在uiimageview中显示图像
我做了以下事情:
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];
没有显示图像。我做错了什么?
答案 0 :(得分:0)
在ios7上,我设法通过更改来解决问题:
[alert addSubview imageView];
与
[alert setValue:imageView forKey@"accessoryView"];
答案 1 :(得分:0)
由于存在拼写错误(您缺少@
字符),因此您没有首先加载图像。您是否收到编译器错误/警告?
尝试替换此行:
UIImage *image = [UIImage imageNamed:"myImg.png"];
有了这个:
UIImage *image = [UIImage imageNamed:@"myImg.png"];