显然没有 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/