Чтобы предотвратить медленную загрузку / прокрутку, используйте изображение-заполнитель. Пример кода ниже показывает, как разогреть изображения.
class YourViewController: UIViewController {
var preheater = ImagePreheater(pipeline: ImagePipeline.shared)
var requests: [ImageRequest]?
// You need to populate remoteImages with the URLs you want prefetched
var remoteImages = [URL]()
override func viewDidLoad() {
super.viewDidLoad()
fetchImages()
}
func fetchImages() {
requests = remoteImages.map {
var request = ImageRequest(url: $0)
request.priority = .high
return request
}
if let requests = requests, requests.count > 0 {
preheater.startPreheating(with: requests)
}
}
deinit {
if let requests = requests, requests.count > 0 {
preheater.stopPreheating(with: requests)
}
}
// This is your code modified to use placeholder
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = carTableView.dequeueReusableCell(withIdentifier: "CarDetailsTableViewCell") as! CarDetailsTableViewCell
if let model = Obj![indexPath.row].model{
cell.nameLabel.text = model
}
if let url = Obj![indexPath.row].image{
let imageURL = URL(string: url)
Nuke.loadImage(with: imageURL!, options: ImageLoadingOptions(
placeholder: UIImage(named: "your-placeholder-image"),
transition: .fadeIn(duration: 0.20)
), into: cell.carImage)
}
return cell
}
}