【发布时间】:2016-08-08 12:41:49
【问题描述】:
我使用此代码在 UICollectionView 中显示一些图像,但可以说单元格是 25。当我下到最后一个单元格然后我尝试上到第一个单元格时,图像再次加载(从缓存但它仍然显示加载指示器。 我的手机是 iPhone SE,我没有很多应用程序,手机运行完美。如果我将我的应用程序加载到上面有很多数据的旧 iphone 上,那么滚动它就会变得粘滞并且非常烦人。我们如何避免在索引路径中的项目的集合视图函数单元格内发生这种情况???
let cell = collectionView.dequeueReusableCellWithReuseIdentifier("RecipesCell", forIndexPath: indexPath) as! RecipesCell
// Get Cover image
let myCache = ImageCache(name: recipesClass.objectId!)
let queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0)
let optionInfo: KingfisherOptionsInfo = [
.DownloadPriority(0.5),
.CallbackDispatchQueue(queue),
.Transition(ImageTransition.Fade(1)),
.TargetCache(myCache)
]
if let imageFile = recipesClass[RECIPES_COVER] as? PFFile {
let URL = NSURL(string: imageFile.url!)!
cell.coverImage.kf_setImageWithURL(URL, placeholderImage: nil,
optionsInfo: optionInfo,
progressBlock: { receivedSize, totalSize in
print("\(indexPath.row + 1): \(receivedSize)/\(totalSize)")
},
completionHandler: { image, error, cacheType, imageURL in
print("\(indexPath.row + 1): Finished")
print("cacheType: \(cacheType) \(indexPath.row + 1): Finished")
})
} else {
cell.coverImage.image = UIImage(named:"logo")
}
有人有同样的问题吗? 谢谢!
仅供参考,我正在使用解析和翠鸟进行缓存
【问题讨论】:
标签: swift swift2 uicollectionview uicollectionviewcell