本文介绍了带有Firebase存储的翠鸟无法缓慢显示图像-Swift 3的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将图像从拾取器保存到Firebase.然后,我将它们放回我的Tableview中,但它们从翠鸟那里的更新非常缓慢.甚至从缓存中.如果我离线加载应用程序,它们仍然需要时间才能显示

Im saving images from a picker up to firebase. Then I'm bringing them back down to my Tableview, but they update really slowly from kingfisher. even from the cache. If I reload the app offline, they still take time to appear

节省Firebase存储空间

Saving up to Firebase Storage

    func Save(image:UIImage, folderName:String, storeRefString:String,         dbRefString:String) {
        let ref = FIRDatabase.database().reference(withPath: "Main")
        let database = FIRDatabase.database()
        let storage = FIRStorage.storage()
        let mainScreenItem = MainItem(name: folderName, image: "")
        let mainItemRef = ref.child(folderName.lowercased())
        let storageRef = storage.reference().child(storeRefString)
        mainItemRef.setValue(mainScreenItem.toAnyObject())

        let fileData = UIImagePNGRepresentation(image)! as NSData

        storageRef.put(fileData as Data).observe(.success) { (snapshot) in
            let downloadURL = snapshot.metadata?.downloadURL()?.absoluteString
            let dbRef = database.reference().child(dbRefString)
            dbRef.setValue(downloadURL)

        }
    }

ViewDidLoad()

ViewDidLoad()

 override func viewDidLoad() {
    super.viewDidLoad()
    maxHeaderHeight = 100
    minHeaderHeight = 50
    ref.queryOrdered(byChild: "name").observe(.value, with: { snapshot in
        var newItems: [MainItem] = []
        for item in snapshot.children {
            let groceryItem = MainItem(snapshot: item as! FIRDataSnapshot)
            newItems.append(groceryItem)
        }
        self.items = newItems
        self.tableView.reloadData()

    })
}

CellForRowAtIndexPath

CellForRowAtIndexPath

    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    let cell = self.tableView.dequeueReusableCell(withIdentifier: "MainTableViewCell") as! MainTableViewCell
    let item = items[indexPath.row]
    let url = URL(string: item.image)
    DispatchQueue.main.async {
        () -> Void in
        cell.photoImage?.kf.setImage(with: url)
    }
    return cell
}

推荐答案

我减小了图像的大小.这似乎可以解决问题

I reduced the size of the images. this seemed to fix the issue

这篇关于带有Firebase存储的翠鸟无法缓慢显示图像-Swift 3的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-02 08:55