一、 今日做项目遇到图片复用问题,返回cell高度相同,由于网络不好出现图片复用,发现问题
Cell 图片加载方法如下:
- (void)sd_setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder {
[selfsd_setImageWithURL:url placeholderImage:placeholder options:0progress:nilcompleted:nil];
}
更改为:
- (void)sd_setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options {
[selfsd_setImageWithURL:url placeholderImage:placeholder options:options progress:nilcompleted:nil];
}
options 方法如下:
/**
* By default, when a URL fail to be downloaded, the URL is blacklisted so the library won‘t keep trying.
* This flag disable this blacklisting.
失败后重新下载
*/
SDWebImageRetryFailed = 1 << 0,
/**
* By default, image downloads are started during UI interactions, this flags disable this feature,
* leading to delayed download on UIScrollView deceleration for instance.
Scrollview 滑动的时候,或者交互的时候,禁止下载图片,等非滑动时刻开始下载,默认情况下,图片会在交互发生的时候下载(例如你滑动tableview的时候),这个flag会禁止这个特性,导致的结果就是在scrollview减速的时候才会开始下载
*/
SDWebImageLowPriority = 1 << 1,
/**
* This flag disables on-disk caching
禁止磁盘缓存
*/
SDWebImageCacheMemoryOnly = 1 << 2,
/**
* This flag enables progressive download, the image is displayed progressively during download as a browser would do.
* By default, the image is only displayed once completely downloaded.
图片逐步下载,这个flag会使图片边下载边显示,不用此方法是下载完成再一次性显示
*/
SDWebImageProgressiveDownload = 1 << 3,
/**
* Even if the image is cached, respect the HTTP response cache control, and refresh the image from remote location if needed.
* The disk caching will be handled by NSURLCache instead of SDWebImage leading to slight performance degradation.
* This option helps deal with images changing behind the same request URL, e.g. Facebook graph api profile pics.
* If a cached image is refreshed, the completion block is called once with the cached image and again with the final image.
*
* Use this flag only if you can‘t make your URLs static with embedded cache busting parameter.
更换头像的时候使用
*/
SDWebImageRefreshCached = 1 << 4,
/**
* In iOS 4+, continue the download of the image if the app goes to background. This is achieved by asking the system for
* extra time in background to let the request finish. If the background task expires the operation will be cancelled.
返回后台继续下载图片
*/
SDWebImageContinueInBackground = 1 << 5,
/**
* Handles cookies stored in NSHTTPCookieStore by setting
* NSMutableURLRequest.HTTPShouldHandleCookies = YES;
使用Cookies的方法
*/
SDWebImageHandleCookies = 1 << 6,
/**
* Enable to allow untrusted SSL certificates.
* Useful for testing purposes. Use with caution in production.
允许不被信任的SSL证书
*/
SDWebImageAllowInvalidSSLCertificates = 1 << 7,
/**
* By default, images are loaded in the order in which they were queued. This flag moves them to
* the front of the queue.
图片下载优先级最高,优先下载图片
*/
SDWebImageHighPriority = 1 << 8,
/**
* By default, placeholder images are loaded while the image is loading. This flag will delay the loading
* of the placeholder image until after the image has finished loading.
默认情况下,占位图会在图片下载的时候显示.这个flag开启会延迟占位图显示的时间,等到图片下载完成之后才会显示占位图(有何意义?
*/
SDWebImageDelayPlaceholder = 1 << 9,
/**
* We usually don‘t call transformDownloadedImage delegate method on animated images,
* as most transformation code would mangle it.
* Use this flag to transform them anyway.
我们通常不会在动画图像上调用transformDownloadedImage委托方法,因为大多数转换代码会对它进行转换,使用此标志来转换它们
*/
SDWebImageTransformAnimatedImage = 1 << 10,
/**
* By default, image is added to the imageView after download. But in some cases, we want to
* have the hand before setting the image (apply a filter or add it with cross-fade animation for instance)
* Use this flag if you want to manually set the image in the completion when success
在图片下载完,显示处理之后的图片
*/
SDWebImageAvoidAutoSetImage = 1 << 11