只言片语 - cell 图片复用问题

一、 今日做项目遇到图片复用问题,返回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

时间: 2024-08-01 23:47:10

只言片语 - cell 图片复用问题的相关文章

iOS开发项目篇—46时间和来源的处理(cell的复用问题)

iOS开发项目篇—46时间和来源的处理(cell的复用问题)一.简单说明 1.存在的问题:             2.问题描述: 刷新微博界面后,展示的最新的微博数据时间显示为“刚刚”,在项目中对时间进行设计的时候,如果是在1分钟之内发表的,那么显示为“刚刚”.查看后面的微博数据后,回过头来(1分钟已经过去了),此时之前显示为“刚刚”的微博,应该显示XX分钟以前,确实显示了,但是时间的frame不正确(此时的frame=="刚刚"两个字的frame). 提示:cell的复用问题,为了

SDWebImage在UITableView部分CELL图片无法加载的解决办法

开始在cell中是使用这个函数来加载图片的. [self.photoView sd_setImageWithURL:[NSURL URLWithString: [post objectForKey: @"thumb_url"]] completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {...} 非常简洁的API,好舒服.但是在tableview第一次加载数据的时候

多线程(四)之cell图片下载(SDWebImage的认识总结)

1.SDWebImage 首先这是个很有名的第三方框架,功能主要是:图片下载,图片缓存,下载进度监听和gif处理等.. 本次的目的是了解一下底层实现和框架的使用. 1.仿写SDWebImage 1.1自定义下载图片的NSOperation 实现起来很简单:思路如下: 1.我要下载图片在模拟器或者真机显示,肯定第一步就是在sb中拉一个imageview控件. 2.肯定要在控制器中设置一个全局属性的queue队列,一般是要懒加载一下,目的也就是实例化队列queue. 3.然后就是采用多线程中的NSO

Tableview 优化Cell的复用机制01

#import "ViewController.h" @interface ViewController ()<UITableViewDataSource> @end @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; UITableView *tab=[[UITableView alloc]init]; tab.frame=self.view.bounds; tab.dataS

iOS开发实践之cell下载图片(自定义NSOperation)

上一篇文章的下载图片操作都放在了block中,当遇到复杂的操作,一堆的代码放在block中 ,很明显这不是明智的选择,代码显得很臃肿. 因此,把线程操作放到自定义NSOperation中. 自定义NSOperation的步骤:继承NSOperation.重写- (void)main方法,在里面实现想执行的任务. 重写- (void)main方法的注意点: 1.自己创建自动释放池(因为如果是异步操作,无法访问主线程的自动释放池). 2.经常通过- (BOOL)isCancelled方法检测操作是否

tableview 点击cell改变cell中的label.text的字体颜色,cell复用出现问题的解决方案2

关于Cell的复用问题,上次已经说了一种,但似乎那种方法不是最好的,所以说,今天下午根据别人提示,想到了此方法.还是老样子,可能不是最好的,但是实现了功能,至少比上次的要好一些. 题目要求:定义固定数据源,然后让tableview的行上各自显示第几行,然后点击选中的时候,字体颜色会变为红色,取消选中的时候字体变为黑色.然后最后的时候要输出选中的结果 解题思路:首先实现tableView的几个协议,然后定义一个模型,在模型中定义一个标识,然后通过点中的时候标识,然后判断标识解决Cell的复用. M

iOS开发实践之cell下载图片(NSOperation)

滚动列表cell的图片从服务器上下载显示,利用多线程和缓存技术 高效下载显示图片. cell下载图片思路: 1.定义images字典存放下载后的图片(图片下载url作为key,图片作为value)cell图片先去images字典中找,没有就往下(沙盒中查找). 2.查找沙盒是否存在,若存在就设置cell图片,否则显示占位图片(增强体验感)并开启线程下载图片. 3.定义字典operations存放所有的下载操作(url是key,operation对象是value).判断下载操作是否存在,若存在 说

三种cell的自定义的方法

(一)纯代码实现自定义cell 1.主要目的实现在创建cell的时候,只用执行两个步骤 1)类方法创建cell(将复用机制,和自定义cell控件,控件的位置封装到cell的类方法中,这里注意要添加一个参数,就是cell是那个tableView的cell这个参数) 2)向cell传递一个数据模型,既可以实现cell的数据更新(既在cell类模型数据的set方法中,实现cell中数据的更新) 3)如果cell中有点击事件,可以通过代理的方式向主控制器中传递事件 2.关键代码 1 #import <U

iOS tableViewCell 在cell赋值、网络加载照片位置偏移大小错乱,做一个类似qq列表的tableview

需求: 类似QQ列表的头像加载刷新,判断在线离线状态改变头像,以及彩色头像灰色处理,下载图片+获取在线状态需要连网--再改变头像 问题:由于cell的复用以及下拉刷新数据每次加载10条数据,会出现头像赋值不正确,位置偏移大小不同的变化 原因:由于cell的重复调用,加载数据方法已经赋值方法也在重复的调用,所以头像加载 在线状态判断好后,网络延迟, (个人开始yy:启动时的cell和赋值结束的cell可能不是同一个) 修改:当cell开始调用的时候,给当前的cell赋tag值,加载结束判断是不是自