【问题标题】:iphone: Smart way to cache large number of images?iphone:缓存大量图像的智能方法?
【发布时间】:2011-09-08 16:05:09
【问题描述】:

我有一个 UITableView,它显示了从网上下载的数百张图片。当然,我不想将所有图像都保存在 RAM 中——我需要在 RAM 中创建一个小的图像“缓存”,并将我现在不需要的图像写入“磁盘”。当然我不希望这种机制阻碍 UI(在主线程上对磁盘/闪存驱动器进行太多读写)。实现这样的事情的最好和最简单的方法是什么?有没有使用这种东西的开源项目,我可以看看?

【问题讨论】:

    标签: iphone cocoa-touch image ipad caching


    【解决方案1】:

    查看Three20 库,尤其是 TTURLRequest、TTURLCache 和 TTImageView 类。

    【讨论】:

      【解决方案2】:

      我最终使用了SDWebImage 非常简单优雅。

      【讨论】:

        【解决方案3】:

        我有一个将 UIImage 存储在 NSMutableDictionary 中的类。如果 UIImage 已经存在于字典中,那么我只返回该对象而不是创建新的 UIImage。

        #import “Cache.h" @implementation Cache static NSMutableDictionary *dict; + (UIImage*)loadImageFromWeb:(NSString*)imageName{ if (!dict) dict = [[NSMutableDictionary dictionary] retain]; UIImage* image = [dict objectForKey:imageName]; if (!image) { image = [UIImage imageWithData: [NSData dataWithContentsOfURL: [NSURL URLWithString: imageName]]]; if (image) { [dict setObject:image forKey:imageName]; } } return image; }

        【讨论】:

        • -1 将所有图像保存在 RAM 中...这是海报明确想要避免的。
        猜你喜欢
        • 1970-01-01
        • 2011-04-05
        • 2011-08-02
        • 2012-08-09
        • 2012-07-20
        • 2011-01-16
        • 1970-01-01
        • 2021-05-17
        • 2011-03-29
        相关资源
        最近更新 更多