ios - 根据 Firebase 值从 NSMutableDictionary() 中删除值
问题描述
我定义var dictImages = NSMutableDictionary()
存储下载的图像并且不加载超过一次,但是当我从tableView
in 中删除行时Firebase
,图像正在滑动。我发现问题出在dictImages
. 防止该错误的唯一方法是编写
dictImages.removeAllObjects()
在下载图像之前,但是在这种情况下没有存储图像的意义,并且效率不高。我需要找出以前存储的项目并将其删除。
这段代码是用以下cellForRowAt
函数编写的tableView
:
if let image = self.dictImages.object(forKey: indexPath)
{
cell?.newsImg.image = image as? UIImage
}
else{
storageRef.getData(maxSize: 1 * 1024 * 1024) { data, error in
if let error = error {
print(error)
} else {
if let data = data
{
let image = UIImage(data: data)
self.dictImages.setObject(image, forKey: indexPath as NSCopying)
cell?.newsImg.image = image
}
}
}
解决方案
推荐阅读
- node.js - 有没有办法在谷歌助手上同时说话和播放音频文件
- go - 如何在 CircleCI Go 图像中使用 Terraform
- android - android studio Gradle 同步失败:不知道如何为 org.gradle.tooling.internal.gradle 构建模型
- openvpn - OpenVPN ping windows 服务器
- mysql - 这个sql查询能不能写得更好
- php - 如何统计在线用户?
- c# - C# 在 SqlDataReader 中禁用自动格式化
- java - 如何使用 Tika API 查找 .bat 文件的 mime 类型?
- reactjs - 设置 React Router 的优先级
- idris - 我可以避免在 Idris 的全部功能中明确排除无效案例吗?