【问题标题】:Deleting tableview image from Firebase Storage从 Firebase 存储中删除 tableview 图像
【发布时间】:2019-06-11 14:42:54
【问题描述】:

我有一个表格视图,其中包含用户将上传的图像。现在,如果用户不再需要该图像,我将尝试添加删除按钮。

也许我只是脑子很累,找不到解决办法,但我觉得我现在有点卡住了。

因此,当我单击 tableview 行时。 (DidSelectRow) 它应该检索 Firebase 存储映像名称。如下图:

here you go

我不明白如何从 tableview 获取文件名。你知道吗?

func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath)
{
    deletePathFromArray = indexPath.row
    deleteName = UUID().uuidString
    print(indexPath)
}

这就是我迄今为止所做的。 (deletePathFromArray 只会从 tableview 中删除它,而不是从存储中删除)

我也有这个:

let deleteRef = storageRef.child(deleteName)
        deleteRef.delete { (err) in
            if let err = err
            {
                print(err.localizedDescription)
            }
            else
            {
                print("Successfully deleted image!")
            }
        }

【问题讨论】:

    标签: ios swift firebase firebase-storage


    【解决方案1】:

    方法就是问题...这是一个概念性的答案,将提供有关整体结构和流程的方向。

    当图片为uploaded to Storage 时,您将获得一个引用该图片的网址。该引用应存储在 Firestore 或 RTDB 中。

    您的 tableView 应该是backed by a dataSource。最初加载图像时,典型的设计模式是具有表示该数据的类或结构。例如在 RTDB 中我们会有

    users_images
        uid_0
           image_id_0 //created with .childByAutoId
              image_url: "http.... reference to the image in Storage"
              title: "My Visit To Paris"
    

    还有一个可以容纳它的类

    class UserImageClass {
       var key = ""
       var uid = ""
       var title = ""
       var url = ""
    }
    

    然后将这些类存储在一个数组中,这是您的 tableView 的数据源

    class ViewController: NSViewController {
        var imagesArray = [UserImageClass]()
    

    从那里如果用户滑动删除,您将知道他们滑动的行的索引,然后您可以从 dataSource 数组中获取对象。由此,您将知道存储中图像的url引用,因此可以删除它,然后还有RTDB中节点的密钥,以便可以删除。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-08-13
      • 2018-03-15
      • 2021-04-25
      • 2022-01-11
      • 2020-03-21
      • 1970-01-01
      • 1970-01-01
      • 2017-01-14
      相关资源
      最近更新 更多