问题
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