怎么样?用的UITableViewCell通过的UIImageView ASINetworkQueue异步加载 [英] How? UITableViewCell with UIImageView asynchronously loaded via ASINetworkQueue

查看:131
本文介绍了怎么样?用的UITableViewCell通过的UIImageView 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/

没有任何人有任何提示/解决方案/ code为与 ASIHTT prequest 图书馆这样做呢?

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

这篇关于怎么样?用的UITableViewCell通过的UIImageView ASINetworkQueue异步加载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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