我将图像从拾取器保存到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
}
答案 0 :(得分:0)
我缩小了图像的大小。这似乎解决了这个问题