Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/106.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 在uialerview中显示nsdata(图像)_Ios_Uiimageview_Uiimage_Nsdata - Fatal编程技术网

Ios 在uialerview中显示nsdata(图像)

Ios 在uialerview中显示nsdata(图像),ios,uiimageview,uiimage,nsdata,Ios,Uiimageview,Uiimage,Nsdata,我确实使用以下方法转换了图像: UIImage *image = [UIImage imageNamed:"myImg.png"]; NSData *myData = UIImagePNGRepresentation(image); //我必须转换它,因为我正在将它发送到服务器 在服务器端接收到NSData后,我现在想在uiimageview中显示该图像 我做了以下工作: UIImage *convImg = [UIImage imageWithData:myData]; UIAler

我确实使用以下方法转换了图像:

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];

没有显示任何图像。我做错了什么?

在ios7上,我通过更改以下内容来解决问题:

[alert addSubview imageView];


您没有首先加载图像,因为有输入错误(您缺少
@
字符)。您是否没有收到编译器错误/警告

尝试替换此行:

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

为此:

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

我知道您正在将“图像”转换为数据以将其发送到服务器,但为什么不使用“图像”作为“图像视图”的图像?另外,如果您在上面的代码中没有使用“convImg”,那么“convImg”的目的是什么?如果您在iOS7中使用它,那么iOS7不允许子视图访问UIAlertView的()
UIImage *image = [UIImage imageNamed:@"myImg.png"];