如何从iOS中的内容获取url图像.帮我?

1 objective-c nsurl uiimageview ios

我有一个如何从URL获取图像的问题.

我试过了:

NSURL *url=[NSURL URLWithString:[NSString stringwithFormat:@"http://kenh14.vn/c102/20120715022212850/ngoc-trinh-la-model-thi-khong-nen-ngai-the-hien.chn"]];
NSURLRequest *request=[NSURLRequest requestWithURL:url];
NSURLConnection *connection=[[NSURLConnection alloc]initWithRequest:request delegate:self startImmediately:NO];
[connection start];

NSData *data=[NSURLConnection sendSynchrounousRequest:request returningResoibse:nil error:nil];
Run Code Online (Sandbox Code Playgroud)

我想用这个图像UIImageView.

lu *_*uan 5

UIImage *img = [UIImage imageWithData:[NSData dataWithContentsOfURL:url]];
Run Code Online (Sandbox Code Playgroud)

来自apple 的示例代码LazyTableImages.app可能就是您想要的.祝好运.