我的应用程序必须从http服务器加载图像并将其显示到UIImageView中
我该怎么做?
我尝试这样做:
Xcode iPhone编程:从URL加载一个JPG到UIImageView
NSString *temp = [NSString alloc];
[temp stringwithString:@"http://192.168.1.2x0/pic/LC.jpg"]
temp=[(NSString *)CFURLCreateStringByAddingPercentEscapes(
nil,
(CFStringRef)temp,
NULL,
NULL,
kCFStringEncodingUTF8)
autorelease];
NSData *dato = [NSData alloc];
dato=[NSData dataWithContentsOfURL:[NSURL URLWithString:temp]];
pic = [pic initWithImage:[UIImage imageWithData:dato]];
这段代码是在视图中的viewDidLoad中不显示任何! 服务器正在工作,因为我可以从中加载xml文件。但我无法显示该图像!
我需要以编程方式加载图像,因为它必须根据传递的参数进行更改! 预先感谢您。 安东尼
: 试试这个,你不需要添加
标签的职位 – 2010-03-24 18:03:16
您的代码看起来很怪异,stringwithString:是一类方法,所以基本上我认为[温度stringwithString:@“HTTP:// 192.168.1.2x0/pic/LC.jpg“]无效。你有没有尝试使用dato = [NSData的dataWithContentsOfURL:[NSURL URLWithString:@“http://192.168.1.2x0/pic/LC.jpg”]]? – zonble 2010-03-24 18:06:10
假设图片是你班上的图像 - 是你想要做的任务吗? (pic = [pic initWithImage ...]) – KevinDTimm 2010-03-24 18:07:34