我正在努力理解如何在我从Listbase中获取的列表视图中缓存图像。我在网上查了一下,大多数解决方案与我写的代码风格有些不同,所以发现很难转移。任何解决方案都会对我在下面提供的课程感激不尽。
class StaffListTableViewCell: UITableViewCell {
@IBOutlet weak var staffFirstAndLastName: UILabel!
@IBOutlet weak var JobTitle: UILabel!
@IBOutlet weak var staffImageView: UIImageView!
var databaseRef: DatabaseReference {
return Database.database().reference()
}
var storageRef: Storage {
return Storage.storage()
}
override func awakeFromNib() {
super.awakeFromNib()
// Initialization code
}
func configureCell(teacher: StaffListsSTRUCT) {
//this line of code helps sets the imageviews in the list view to nil before loading.
self.staffImageView.image = nil
self.staffFirstAndLastName.text = teacher.staffName
self.JobTitle.text = teacher.staffJobTitle
let imageURL = teacher.staffImageViewString!
self.storageRef.reference(forURL: imageURL).getData(maxSize: 1 * 1024 * 1024, completion: { (imgData,
error) in
if error == nil {
DispatchQueue.main.async {
if let data = imgData {
self.staffImageView.image = UIImage(data: data)
}
}
} else {
print(error!.localizedDescription)
}
})
}
}