Kingfisher with Firebase storage slow to display images - swift 3

混江龙づ霸主 提交于 2019-12-12 02:36:22

问题


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

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()

 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

    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
}

回答1:


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



来源:https://stackoverflow.com/questions/43305338/kingfisher-with-firebase-storage-slow-to-display-images-swift-3

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!