如何在没有任何缓存的情况下为一个实例使用SDWebImage

编程入门 行业动态 更新时间:2024-10-09 22:21:17
本文介绍了如何在没有任何缓存的情况下为一个实例使用SDWebImage的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我在桌面上显示图像时几乎都使用 SDWebImage 图像下载/缓存库查看。

I use the SDWebImage image downloading/caching library pretty much any time I display an image in a table view.

我通常会这样实现它(在表视图中 cellForRowAtIndexPath 方法)。

I would usually implement it like so (in a table view cellForRowAtIndexPath method).

[cell.imageView setImageWithURL: [NSURL URLWithString:@"asite/animage.jpg"] placeholderImage:[UIImage imageNamed:@"placeholder.png"]];

这会加载缓存版本(如果有的话)。

And that would load a cached version if it had one.

如果我想使用SDWebImage的简单性(使用占位符/强大的下载代码) - 但只有一个地方没有缓存那么。

What about if I wanted to use the simplicity of SDWebImage (with the placeholder / robust downloading code) - but without the cache in just one place.

我知道如何在整个SDWebImage中禁用缓存,但我不知道如何调用 setImageWithUrl:placeholderImage:确保SDWebImage没有t使用任何缓存?

I know how to disable caching throughout SDWebImage, but I don't know how you would call setImageWithUrl: placeholderImage: making sure that SDWebImage doesn't use any cache?

我想这样做的原因是我用它来在桌面视图中显示网络摄像头(显然,你希望每次都更新) 。

The reason I want to do this is I'm using it to display webcams in a table view (obviously, you want this updated every time).

推荐答案

我建议远离UIImageView上的类别并创建自己的SDWebImageManager版本。如果您自己使用SDImageCache类,您将获得更多控制权。

I recommend moving away from the Category on UIImageView and creating your own version of SDWebImageManager. You'd get more control if you use the class SDImageCache yourself.

来自SDWebImageManager本身的Heres和示例:

Heres and example right from SDWebImageManager itself:

[[SDImageCache sharedImageCache] storeImage:image imageData:downloader.imageData forKey:[downloader.url absoluteString] toDisk:NO];

toDisk可能是我将BOOL更改为NO的地方,默认管理器使用磁盘缓存。您可能还需要经常清理内存以支持您的流媒体图像:

toDisk is probably where I changed the BOOL to NO, the default manager uses disk caching. You may also want to clear the memory every so often to support your streaming images:

[[SDImageCache sharedImageCache] clearMemory];

SDWebImageManager代码很容易理解,我想你不需要重新发明大部分代码,只需几个重要部分来满足您的需求。

The SDWebImageManager code is easy to follow and I imagine you won't need to reinvent most of it, just a few important portions to suit your needs.

更多推荐

如何在没有任何缓存的情况下为一个实例使用SDWebImage

本文发布于:2023-11-17 10:51:59,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1609784.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:没有任何   缓存   实例   情况下   如何在

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!