我的应用程序必须从http服务器加载图像并将其显示到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]];
Run Code Online (Sandbox Code Playgroud)
此代码在视图的viewdidload中,但没有显示任何内容!服务器正在运行,因为我可以从中加载xml文件.但我不能显示那个图像!
我需要以编程方式加载图像,因为它必须根据传递的参数进行更改!先感谢您.安东尼奥