Ios 将imageCache中的图像设置为imageCache的开头,而不是结尾
我使用以下命令将对象设置到imageCache:Ios 将imageCache中的图像设置为imageCache的开头,而不是结尾,ios,swift,uitableview,object,caching,Ios,Swift,Uitableview,Object,Caching,我使用以下命令将对象设置到imageCache: self.picPostPicImageCache.setObject(UIImage(data:imageData)!,forKey: urlString as NSString) } 这在tableview中使用,如下所示: let cell : ImagePostTableViewCell = BarSelectedTableView.dequeueReusableCel
self.picPostPicImageCache.setObject(UIImage(data:imageData)!,forKey: urlString as NSString)
}
这在tableview中使用,如下所示:
let cell : ImagePostTableViewCell = BarSelectedTableView.dequeueReusableCell(withIdentifier: "ImagePostTableViewCell", for: indexPath) as! ImagePostTableViewCell
if let PicPostCacheImage = picPostPicImageCache.object(forKey: picPostPicUrlArray[indexPath.row] as NSString) { if let PicProPicCacheImage = picPostProPicImageCache.object(forKey: picPostProPicUrlArray[indexPath.row] as NSString) {
cell.userImagePostView.image = PicPostCacheImage
cell.userImageView.image = PicProPicCacheImage
}
} else {
cell.userImagePostView.sd_setImage(with: URL(string: picPostPicUrlArray[indexPath.row] as String), placeholderImage: UIImage(named: "defaultPropic"), options: [.continueInBackground, .progressiveLoad])
cell.userImageView.sd_setImage(with: URL(string: picPostProPicUrlArray[indexPath.row] as String), placeholderImage: UIImage(named: "defaultPropic"), options: [.continueInBackground, .progressiveLoad])
}
我遇到的问题是当我想向缓存中添加新照片时。目前,我使用相同的方法添加一张像这样的新照片
self.picPostPicImageCache.setObject(UIImage(data:imageData)!,forKey: urlString as NSString)// new photo
但是,这会将图像添加到缓存的末尾,并将图像显示在tableview的底部,而不是顶部。我想将其添加到缓存的开头。在不删除缓存中的元素并重新加载的情况下,有没有可能做到这一点