Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/114.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/22.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 NSData到uiimage返回null_Ios_Objective C_Iphone_Uiimageview_Uiimage - Fatal编程技术网

Ios NSData到uiimage返回null

Ios NSData到uiimage返回null,ios,objective-c,iphone,uiimageview,uiimage,Ios,Objective C,Iphone,Uiimageview,Uiimage,_pageImages是可更改的。我正在存储图像url _pageImages = [[NSMutableArray alloc]initWithObjects:@"https://api.url2png.com/v3/P4DE5D1C99D8EF/7bbb6e0d1b74fb0ae1d4f18b06320096/400x400/abc.com",@"https://api.url2png.com/v3/P4DE5D1C99D8EF/7bbb6e0d1b74fb0ae1d4f18b0632009

_pageImages是可更改的。我正在存储图像url

_pageImages = [[NSMutableArray alloc]initWithObjects:@"https://api.url2png.com/v3/P4DE5D1C99D8EF/7bbb6e0d1b74fb0ae1d4f18b06320096/400x400/abc.com",@"https://api.url2png.com/v3/P4DE5D1C99D8EF/7bbb6e0d1b74fb0ae1d4f18b06320096/400x400/abc.com", nil];
要在uiimageview中显示此url图像

NSURL *url = [NSURL URLWithString:[_pageImages objectAtIndex:i]];

NSData *data = [[NSData alloc] initWithContentsOfURL:url];

UIImage *tmpImage = [UIImage imageWithData:data];

_backgroundImageView.frame = CGRectMake(0 ,10, 320, 320);

 _backgroundImageView.image = tmpImage;

  [self.view addSubview:_backgroundImageView];

我看到了很多例子,但我不能得到正确的解决方案。新的发展模式。帮助我..

通过发送
异步请求下载图像来尝试此操作--


通过发送
AsynchronousRequest
下载图像来尝试此操作--


问题出在URL中

尝试访问你的图片URL,我得到的只是“未经授权”

运行这个示例代码,您的代码,只是使用不同的图像地址。 检查图像地址是否正确,它应按预期运行

NSMutableArray *pageImages = [[NSMutableArray alloc]initWithObjects:@"http://findicons.com/files/icons/1636/file_icons_vs_3/128/url.png",@"http://findicons.com/files/icons/1636/file_icons_vs_3/128/pdf.png", nil];

NSURL *url = [NSURL URLWithString:[pageImages objectAtIndex:0]];

NSData *data = [[NSData alloc] initWithContentsOfURL:url];

UIImage *tmpImage = [UIImage imageWithData:data];

_depImage.frame = CGRectMake(0 ,10, 320, 320);
_depImage.image = tmpImage;

问题出在URL中

尝试访问你的图片URL,我得到的只是“未经授权”

运行这个示例代码,您的代码,只是使用不同的图像地址。 检查图像地址是否正确,它应按预期运行

NSMutableArray *pageImages = [[NSMutableArray alloc]initWithObjects:@"http://findicons.com/files/icons/1636/file_icons_vs_3/128/url.png",@"http://findicons.com/files/icons/1636/file_icons_vs_3/128/pdf.png", nil];

NSURL *url = [NSURL URLWithString:[pageImages objectAtIndex:0]];

NSData *data = [[NSData alloc] initWithContentsOfURL:url];

UIImage *tmpImage = [UIImage imageWithData:data];

_depImage.frame = CGRectMake(0 ,10, 320, 320);
_depImage.image = tmpImage;

我们可以简单地使用以下命令从URL加载图像数据

_backgroundImageView.image = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLwithString:urlString]]];
这里不需要打服务电话


希望对您有所帮助。

我们可以简单地使用以下命令从URL加载图像数据

_backgroundImageView.image = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLwithString:urlString]]];
这里不需要打服务电话


希望对您有所帮助。

您是否检查过您的数据是否为零?原因可能是您忘记了禁用目标域的应用程序传输安全性(当我自己尝试时,我在浏览器中遇到错误…)是的,使用返回
NSError
对象的方法(例如
initWithContentsOfURL:options:error:
)如何,它错误地显示我更改了url,但仍然存在UIImage*tmpImage=[UIImage imageWithData:data];。。。tmpImage返回空..您是否检查了数据是否为空?原因可能是您忘记了禁用目标域的应用程序传输安全性(当我自己尝试时,我在浏览器中遇到错误…)是的,使用返回
NSError
对象的方法(例如
initWithContentsOfURL:options:error:
)如何,它错误地显示我更改了url,但仍然存在UIImage*tmpImage=[UIImage imageWithData:data];。。。tmpImage返回null..我更改了url,但仍然存在UIImage*tmpImage=[UIImage imageWithData:data];。。。tmpImage返回null。\u backgroundImageView.image=tmpImage;是否为空我更改了url,但仍然存在UIImage*tmpImage=[UIImage imageWithData:data];。。。tmpImage返回null。\u backgroundImageView.image=tmpImage;为空\u backgroundImageView.image=tmp图像;是null@Saravananr很高兴帮助你。:)_backgroundImageView.image=tmp图像;是null@Saravananr很高兴帮助你。:)