0

我将图像从选择器保存到 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
}
4

1 回答 1

1

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

于 2017-04-15T08:40:01.780 回答