2.UIView + WebCacheOperation

1. - (NSMutableDictionary *)operationDictionary 
 
 
通过loadOperationKey值 ,将imageview和operations字典进行绑定。 
获取到 loadOperationKey与绑定的imageview 上的 operations 字典 ,如果之前有过绑定,那就会有值。
如果该字典初始化的话,就返回该字典,如果没有,创建一个新的字典,将这个字典和imageview 通过key绑定起来 
 
2. - (void)sd_cancelImageLoadOperationWithKey:(NSString *)key 
 
 
 
从第1步中,找到对应的字典,循环遍历取出字典中的 id<SDWebImageOperation>,然后调用cancel方法,最后将字典中的对应的值删除。
这里的id<SDWebImageOperation>,是遵循了<SDWebImageOperation>协议的对象。 具体是SDWebImageCombinedOperation对象。
 
3. - (void)sd_setImageLoadOperation:(id)operation forKey:(NSString *)key
 
 
调用2 方法,将之前的操作取消掉 。然后通过key,添加operation。
 
4.- (void)sd_removeImageLoadOperationWithKey:(nullable NSString *)key 方法
 
将存储的值,从字典中移除。 
 
总结:
在存时,将operation 和 imageview 绑定起来。 并将key operation 存到数组中。
并且每次存时,将imageview 中字典对应的operation 全部取出,调用cancel方法。
这样做的目的,是当imageview 请求多次网络时,避免多次请求。
 
在取时,将对于的imageview 所关联的字典取出 。
目的是防止同一个imageview 调用多个sd 请求。
 
posted @ 2018-03-30 19:37  我是你们最爱的硕哥  阅读(181)  评论(0编辑  收藏  举报