首页 > 解决方案 > 根据 Firebase 值从 NSMutableDictionary() 中删除值

问题描述

我定义var dictImages = NSMutableDictionary()存储下载的图像并且不加载超过一次,但是当我从tableViewin 中删除行时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
            }
        }
    }

删除行之前

删除行后

标签: iosswiftfirebaseuitableview

解决方案


推荐阅读