在我的Swift应用程序中,我具有以下集合视图。 每次用户看到单元格时,它都会重新加载数据,并且每次从数据库中获取图像时,都会使应用程序变慢。 我怎样才能使一个单元出队一次? 或者我怎么只能加载一次图像?
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
selectedLocal = locals[indexPath.row - Int(indexPath.row / adsDensity)]
let localCell = collectionView.dequeueReusableCell(withReuseIdentifier: "cell", for: indexPath)
localCell.backgroundColor = currentTheme.backgroundColor
localCell.layer.cornerRadius = localCell.frame.width / 32
localCell.layer.shadowRadius = 5
localCell.layer.shadowOpacity = 0.3
localCell.layer.shadowOffset = CGSize(width: 5, height: 10)
localCell.clipsToBounds = true
localCell.coveImageView.layer.masksToBounds = true
localCell.coveImageView.clipsToBounds = true
localCell.coveImageView.setImageFromURl(stringImageUrl: “server_url”)
localCell.titleLabel.text = selectedLocal.title
localCell.placeLabel.text = selectedLocal.city
localCell.timetableLabel.text = "Open"
localCell.titleLabel.textColor = currentTheme.textColor
localCell.placeLabel.textColor = currentTheme.textColor
localCell.timetableLabel.textColor = currentTheme.textColor
localCell.reviewLabel.textColor = currentTheme.textColor
localCell.ratingView.backgroundColor = .clear
localCell.ratingView.contentMode = .scaleAspectFit
localCell.ratingView.emptyImage = imageLiteral(resourceName: "emptyStar")
localCell.ratingView.fullImage = imageLiteral(resourceName: "fullyStar")
localCell.ratingView.rating = selectedLocal.rating
return localCell
}