小编Ant*_*gia的帖子

Xcode iPhone编程:从URL将jpg加载到UIImageView中

我的应用程序必须从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文件.但我不能显示那个图像!
我需要以编程方式加载图像,因为它必须根据传递的参数进行更改!先感谢您.安东尼奥

iphone url xcode objective-c uiimageview

21
推荐指数
2
解决办法
7万
查看次数

标签 统计

iphone ×1

objective-c ×1

uiimageview ×1

url ×1

xcode ×1