如何使用AFNetworking 2.0下载图像? [英] How to download image with AFNetworking 2.0?

查看:92
本文介绍了如何使用AFNetworking 2.0下载图像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

显然没有 AFImageRequestOperation ,但只有 AFImageResponseSerializer 而坦率地说我没有得到它或者我可能通过AFNetworking网站看起来太长了...用以前的AFNetworking下载图像就像一个魅力。我不想回到旧的AFnetworking,因为我通过新版本做了几乎所有的东西......任何人?

Appareantly there is no AFImageRequestOperation, but only AFImageResponseSerializer and frankly I don't get it or maybe I'm just looking too long through AFNetworking site... Downloading images with previous AFNetworking was like a charm. I'd hate to go back to older AFnetworking, since I did almost all stuff via the new version... Anyone?

推荐答案

所以你想要2.0这样的东西。

SO you want something like this for 2.0.

AFHTTPRequestOperation *requestOperation = [[AFHTTPRequestOperation alloc] initWithRequest:urlRequest];
requestOperation.responseSerializer = [AFImageResponseSerializer serializer];
[requestOperation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
    NSLog(@"Response: %@", responseObject);
    _imageView.image = responseObject;

} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
    NSLog(@"Image error: %@", error);
}];
[requestOperation start];

正如亚当所提到的,如果你只想把它扔进去,你也可以做下面的事情。一个imageView

As mentioned by Adam you can also do something like the below if you are just wanting to throw it into an imageView

[myImageView setImageWithURL:[NSURL URLWithString:@"http://sitewithimage.com/images/myimage.png"]];

这篇关于如何使用AFNetworking 2.0下载图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆