我有一个tableview和其中的单元格,它有imageview,它从服务器获取图像,每当用户向下滚动到tableview的末尾时,tableview的数据就会重新加载,但我的问题是单元格图像将在tableview重新加载时再次从服务器下载图像,这是我的代码:
let cell = tableView.dequeueReusableCell(withIdentifier: "pizzacell", for: indexPath) as! CustomPizzaCell
let imgurl = URL(string: "\(BaseUrl)//assests/products/imgs/\(MainMenu.cellarray[indexPath.row].img)")
cell.pizzaimg.kf.setImage(with: imgurl, options: [.downloadPriority(Float(indexPath.row)),.transition(.flipFromTop(1.0)),.forceRefresh,.processor(processor)])
if indexPath.row == MainMenu.cellarray.count-1 {
if !isendoftable {
MainMenu.start += 5
MainMenu.end += 5
var parameters: Parameters = ["START": "\(MainMenu.start)"]
parameters["END"] = "\(MainMenu.end)"
parameters["TYPE"] = "\(MainMenu.type)"
print(parameters)
ApiManager.request(Address: "\(BaseUrl)/admin/Android/getLastProducts", method: .post, parameters: parameters) { json in
self.stopAnimating()
if json == nil {
let popupDialog = PopupDialog(title: "خطای دسترسی به سرور", message: "")
let btn = DefaultButton(title: "تلاش مجدد"){}
btn.titleFont = UIFont(name: "IRANSans(FaNum)", size: 15)
if UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiom.pad {
btn.titleFont = UIFont(name: "IRANSans(FaNum)", size: 17)
}
popupDialog.addButton(btn)
self.present(popupDialog, animated: true, completion: nil)
}
else {
if (json?.array?.isEmpty)! {
MainMenu.start = 0
MainMenu.end = 5
self.isendoftable = true
}
for item in (json?.array)! {
let piiiza = MainMenu.cell(id: item["id"].description, title: item["title"].description, img: item["img"].description)
MainMenu.cellarray.append(piiiza)
}
tableView.reloadData()
}
}
}
}
return cell