1

我从互联网上下载每个表格单元格的文本和图像。我在后台(GCD)中执行此操作,但性能不佳(需要一段时间为所有行的 dll 图像),因为有很多行。

我将 nsurlconnection 用于图像 dll。

我用谷歌搜索了一下,变得困惑。最简单的方法是什么?使用 NSCache(用于图像和文本)还是我必须学习核心数据?

4

4 回答 4

2

您可以使用AsyncImageView下载和缓存图像。

于 2012-07-25T09:07:01.497 回答
1

我使用这个库来兑现网络图像
https://github.com/rs/SDWebImage 非常简单易用

[imageView setImageWithURL:[NSURL URLWithString:yoururl]];

于 2012-07-25T09:01:28.537 回答
1

结帐https://github.com/rs/SDWebImage/一个超级简单的方法来做到这一点......

从自述文件:

[cell.imageView setImageWithURL:[NSURL URLWithString:@"http://www.domain.com/path/to/image.jpg"]
               placeholderImage:[UIImage imageNamed:@"placeholder.png"]];

这就是缓存图像所需的全部内容。您可以查看源代码以了解如何扩展它以支持缓存文本对象。或者,您可以使用NSUserDefaults基于 URL 和文本数据存储键值对。

于 2012-07-25T09:02:39.333 回答
1

我为此使用块和ASIHTTPRequest,它工作正常。

[ASIHTTPRequest setDefaultCache:[ASIDownloadCache sharedCache]];

ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:[NSURL urlWithString:<yoururl>]];
[request setDownloadCache:[ASIDownloadCache sharedCache]];
[request setCachePolicy:ASIOnlyLoadIfNotCachedCachePolicy];
[request setCacheStoragePolicy:ASICacheForSessionDurationCacheStoragePolicy];


[request setCompletionBlock:^{
    //do your things
}];

[request setFailedBlock:^{
     //request failed - inform the user
}];

[request startAsynchronous];
于 2012-07-25T08:59:05.053 回答