如何?通过 ASINetworkQueue 异步加载 UIImageView 的 UITableViewCell [英] How? UITableViewCell with UIImageView asynchronously loaded via ASINetworkQueue
问题描述
我正在尝试使用 ASINetworkQueue
异步加载表格单元格中的一些图像.我只是想不通,似乎也找不到一个好的简单示例.
I'm trying to load some images in table cells asynchronously using ASINetworkQueue
. I just can't figure it out and can't seem to find a good SIMPLE example.
我能找到的最好的是这个,但它只是完全矫枉过正,对我来说有点太复杂了:http://kosmaczewski.net/2009/03/08/asynchronous-loading-of-images-in-a-uitableview/
The best I can find is this, but its just totally overkill and a little too complicated for me: http://kosmaczewski.net/2009/03/08/asynchronous-loading-of-images-in-a-uitableview/
是否有其他人有任何使用 ASIHTTPRequest
库执行此操作的提示/解决方案/代码?
Does anyone else have any tips/solutions/code for doing this with the ASIHTTPRequest
library?
推荐答案
这是我使用的从 UIImageView 派生的类,也许这对您有所帮助.(实际上,我已经从我使用的内容中简化了这一点,但这正是您所要求的!)
Here's a class derived from UIImageView which I use, perhaps this will help you. (Actually I've simplified this a fair bit from what I use, but that was what you asked for!)
头文件,UIHTTPImageView.h:
Header file, UIHTTPImageView.h:
#import "ASIHTTPRequest.h"
@interface UIHTTPImageView : UIImageView {
ASIHTTPRequest *request;
}
- (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder;
@end
和 UIHTTPImageView.m:
and UIHTTPImageView.m:
#import "UIHTTPImageView.h"
@implementation UIHTTPImageView
- (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder {
[request setDelegate:nil];
[request cancel];
[request release];
request = [[ASIHTTPRequest requestWithURL:url] retain];
[request setCacheStoragePolicy:ASICachePermanentlyCacheStoragePolicy];
if (placeholder)
self.image = placeholder;
[request setDelegate:self];
[request startAsynchronous];
}
- (void)dealloc {
[request setDelegate:nil];
[request cancel];
[request release];
[super dealloc];
}
- (void)requestFinished:(ASIHTTPRequest *)req
{
if (request.responseStatusCode != 200)
return;
self.image = [UIImage imageWithData:request.responseData];
}
@end
这篇关于如何?通过 ASINetworkQueue 异步加载 UIImageView 的 UITableViewCell的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!