【问题标题】:Kingfisher with Firebase storage slow to display images - swift 3具有 Firebase 存储的翠鸟显示图像缓慢 - swift 3
【发布时间】:2017-09-04 10:40:32
【问题描述】:

我正在将图像从选择器保存到 firebase。然后我将它们带回我的 Tableview,但它们从翠鸟更新得非常缓慢。甚至从缓存中。如果我离线重新加载应用程序,它们仍然需要一些时间才能出现

保存到 Firebase 存储

    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
}

【问题讨论】:

    标签: firebase swift3 uiimage firebase-storage kingfisher


    【解决方案1】:

    我缩小了图像的大小。这似乎解决了问题

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-09-01
      • 2018-06-11
      • 1970-01-01
      • 2017-08-30
      • 2017-07-17
      • 2020-04-20
      • 2017-12-01
      • 1970-01-01
      相关资源
      最近更新 更多