使用 NSString 和 UIImageView 从 URL 加载图像,在某些 URL 上失败
我有一些代码可以从 URL 加载图像,它似乎工作正常。除非 URL 包含大括号。这看起来像是字符串格式问题?我想不通。
前任 @"http://site/image.png //works
@"http://site/{image}.png //不起作用,
NSString* mapURL = @"http://site.com/directory/{map}.png";
NSLog(mapURL);
NSData* imageData = [[NSData alloc]initWithContentsOfURL:[NSURL URLWithString:mapURL]];
UIImage* image = [[UIImage alloc] initWithData:imageData];
[imageView setImage:image];
[imageData release];
[image release];
谢谢
I've got some code to load an image from a URL, it seems to work ok. Unless the URL contains curly brackets. This seems like it is a string formatting problem? I can't figure it out.
ex
@"http://site/image.png //works
@"http://site/{image}.png //doesn't work
NSString* mapURL = @"http://site.com/directory/{map}.png";
NSLog(mapURL);
NSData* imageData = [[NSData alloc]initWithContentsOfURL:[NSURL URLWithString:mapURL]];
UIImage* image = [[UIImage alloc] initWithData:imageData];
[imageView setImage:image];
[imageData release];
[image release];
thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我发现这很有帮助
http://simonwoodside.com/weblog/2009/4/22 /how_to_really_url_encode/
i found this helpful
http://simonwoodside.com/weblog/2009/4/22/how_to_really_url_encode/