iphone - 如何使用 AFNetworking 2.0 下载图像?

标签 iphone ios xcode afnetworking-2

显然没有 AFImageRequestOperation,只有 AFImageResponseSerializer,坦率地说,我不明白,或者我只是在 AFNetworking 网站上看得太久了……正在下载以前 AFNetworking 的图像就像一个魅力。我不想回到旧的 AFnetworking,因为我几乎所有的事情都是通过新版本完成的……有人吗?

最佳答案

所以你想要 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];

正如 Adam 所提到的,如果您只是想将其放入 imageView,您也可以执行类似下面的操作

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

关于iphone - 如何使用 AFNetworking 2.0 下载图像?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19501652/

相关文章:

iphone - 将我的应用程序提交到 App Store 时出错

iphone - Objective-C 显示来自 Web 服务的 HTML 文件

iphone - UILabel 中心内容

iphone - 应用程序在 3GS 上速度很快,但在 3G 上速度很慢

iphone - 装有 IOS 5.1 的 iPad - 奇怪的崩溃报告

ios - 最后一个 UITableViewCell 上的分隔符没有添加?

ios - 现有项目的 XCTest

iphone - 如何判断 UITableViewCell 内的 UISwitch 何时被点击?

iphone - resignFirstResponder 并从任何地方关闭键盘?

iphone - 通过 IOS 应用程序登录 Facebook 重定向到空白页面