简体   繁体   English

从Firebase存储中删除tableview图像

[英]Deleting tableview image from Firebase Storage

I've a tableview with a images that users will upload. 我有一个用户将上传的图片的tableview。 Now I'm trying to add a delete button if the user does NOT want that image anymore. 现在我正在尝试添加删除按钮,如果用户不再需要该图像。

Maybe I'm just tired in my head and cannot find a solution for this, but I feel like I'm kinda stuck right now. 也许我只是厌倦了,无法找到解决方案,但我觉得我现在有点卡住了。

So when I click on a tableview row. 所以当我点击tableview行时。 (DidSelectRow) it should retrieve the Firebase Storage image name. (DidSelectRow)它应该检索Firebase存储图像名称。 Like the image below: 如下图所示:

here you go 干得好

I do not understand how I can get the filename from the tableview. 我不明白如何从tableview获取文件名。 Do you know? 你知道吗?

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

This is what I've so far. 这是我到目前为止。 (deletePathFromArray will just delete it from the tableview, and not from storage) (deletePathFromArray只会从tableview中删除它,而不是从存储中删除)

Also I've this: 我也是这样的:

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

The approach is the issue... This is a conceptual answer and will provide direction about the overall structure and process. 方法就是问题......这是一个概念性答案,将为整体结构和流程提供方向。

When an image is uploaded to Storage , you will be provided a url which is a refence to that image. 将图像上传到存储时 ,将为您提供一个URL,该URL是对该图像的反射。 That reference should be stored in Firestore or RTDB. 该引用应存储在Firestore或RTDB中。

Your tableView should be backed by a dataSource . 您的tableView应该由dataSource支持 When the images are initially loaded, a typical design pattern is to have a class or struct that represents that data. 最初加载图像时,典型的设计模式是具有表示该数据的类或结构。 For example in the RTDB we would have 例如,我们可以在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"

and a class that would hold that 还有一个能够坚持下去的课程

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

then those classes are stored in an array, which is the dataSource for your tableView 然后这些类存储在一个数组中,该数组是tableView的dataSource

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

From there if a user swipes to delete, you will know the index of the row they swiped, then you can get the object from the dataSource array. 从那里,如果用户滑动删除,您将知道他们刷过的行的索引,然后您可以从dataSource数组中获取该对象。 From that, you will know the url reference to the image in Storage, so it can be deleted and then also the key to the node in the RTDB so that can be deleted. 从那里,您将知道存储中对图像的URL引用,因此可以删除它,然后还可以删除RTDB中节点的键,以便删除它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM