从服务器加载图像到手机中的 UIImageView 上
我在将远程图像加载到 UIImageVIew 时遇到问题... 它只是不显示图像,可能是我遗漏了一些东西...
我也使用此处描述的但具有相同的结果 如何从远程服务器加载图像iphone 中的 UIImageView?
有人可以帮助我吗?
这是我正在使用的代码
我从 xml 获取数据,并且在图像元素上我有完整路径
[[detailViewController detailImage] setImage:[UIImage imageWithData: [NSData dataWithContentsOfURL: [NSURL URLWithString: [NSString stringWithFormat:@"%@", [[promoList objectAtIndex: promoIndex] objectForKey: @"image"]] ]]] ];
使用此代码,图像可以正确显示
[[detailViewController detailImage] setImage:[UIImage imageWithData: [NSData dataWithContentsOfURL: [NSURL URLWithString: @"http://localhost/promos/preview/1.jpeg"]] ]];
I'm having a problem loading a remote image into a UIImageVIew...
It just doesn't show the image, may be i'm missing something...
I also use the described here but with the same results
How to load image from remote server on the UIImageView in iphone?
Can someone help me?
This is the code i'm using
Im getting the data from a xml and on the image element I have the full path
[[detailViewController detailImage] setImage:[UIImage imageWithData: [NSData dataWithContentsOfURL: [NSURL URLWithString: [NSString stringWithFormat:@"%@", [[promoList objectAtIndex: promoIndex] objectForKey: @"image"]] ]]] ];
With this code the image are displayed correctly
[[detailViewController detailImage] setImage:[UIImage imageWithData: [NSData dataWithContentsOfURL: [NSURL URLWithString: @"http://localhost/promos/preview/1.jpeg"]] ]];
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
由于底部示例按预期工作,并且除了 url 字符串之外,该示例看起来相同,因此问题应该是获取 url 字符串。问题还在于代码看起来相同但很难看清。我会将代码重构为:
然后您可以正确调试该语句,并确保在每个步骤后得到您所期望的结果。
更新
要删除换行符和制表符,您可以:
如果 urlObject 已经是一个字符串(它应该是),那么您可以执行以下操作:
这会使它更干净一些。
Since the bottom example works as expected and besides the url string the example looks the same the problem should be with getting the url string. The problem is also that the code looks the same but it is quite hard to see. I would refactor the code to something like:
Then you can debug the statement properly and make sure that you get what you expect after each step.
Update
To remove newline and tabs you can:
If urlObject already is a string, which it should be, then you can do:
which would make it a bit cleaner.