圖像在tableview中沒有正確顯示,我有兩個Json Api(初級/高級)學校。我可以將兩個Json API數據和顯示添加到tableview中, tableview工作正常,它顯示兩個(主/高)學校數據。當我可以滾動tableview圖像跳躍和圖像加載非常緩慢的圖像視圖在tableview。圖像在桌面視圖中滾動時重複單元格
之前滾動的tableview其顯示這樣
滾動它顯示像滾動的圖片後,該
都跳的tableview後,
這是代碼
var kidsdata = [KidDetails]()
func getprimarydata(_firsturl: String,firstid:String,updatedate:String)
{
if errorCode == "0" {
if let kid_list = jsonData["students"] as? NSArray {
self.kidsdata.removeAll()
for i in 0 ..< kid_list.count {
if let kid = kid_list[i] as? NSDictionary {
let imageURL = url+"/images/" + String(describing: kid["photo"]!)
self.kidsdata.append(KidDetails(
name:kid["name"] as? String,
photo : (imageURL),
standard: ((kid["standard"] as? String)! + "std" + " " + (kid["section"] as? String)! + " section ")
))}}}}
}
func gethighdata(_secondurl:String ,secondid:String,updatedate:String)
{
if errorCode == "0" {
if let kid_list = jsonData["students"] as? NSArray {
for i in 0 ..< kid_list.count {
if let kid = kid_list[i] as? NSDictionary {
let imageURL = url+"/images/" + String(describing: kid["photo"]!)
self.kidsdata.append(KidDetails(
name:kid["name"] as? String,
photo : (imageURL),
standard: ((kid["standard"] as? String)! + "th" + " " + (kid["section"] as? String)! + " section ")
)
)
}
}
self.do_table_refresh()
}
}
}
func do_table_refresh()
{
DispatchQueue.main.async(execute: {
self.TableView.reloadData()
return
})
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell =
tableView.dequeueReusableCell(
withIdentifier: "cell", for: indexPath) as! DataTableViewCell
cell.selectionStyle = .none
cell.ProfileImage?.image = nil
let row = (indexPath as NSIndexPath).row
let kid = kidsdata[row] as KidDetails
cell.NameLabel.text = kid.name
cell.ProfileImage.image = UIImage(named: "profile_pic")
cell.ProfileImage.downloadImageFrom(link:kid.photo!, contentMode: UIViewContentMode.scaleAspectFill)
cell.ClassNameLabel.text = kid.standard
return cell
}
,我沒有錯誤請幫助我....!
在您的tableViewCell類中,您需要重置函數'prepareForReuse'中的圖像。這將在每次細胞被重複使用時被調用,並且是可以移除圖像的最難點。該函數在UITableViewCell中實現,你必須覆蓋它 –
啊,你下載一個圖像,這個函數是在後臺線程中運行下載並將圖像放在主線程中? –
這是否證明該單元格是否仍然是請求該照片的單元格? :) –