我的圖片有問題。我的表格視圖很慢。我如何通過異步調用來改進?在創建細胞的功能,我有這樣的:如何異步加載圖像以提高表視圖性能?
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
//IMPOSTA l'identifier della cella campione indexpath restituisce il numero della cella
let cella = tableView.dequeueReusableCellWithIdentifier("record_cat", forIndexPath: indexPath) as! myTableViewCell
if (musica.shared.id.count > 0) && (cella_select < musica.shared.id.count){
//label personalizzata cella con inserimento dell ARRAY IN BASE ALL'INDICE (indexPath.row indica il numero della cella quindi associa cella ad array)
print(indexPath.row)
cella.button_favorite.tag = indexPath.row
cella.titolo.text = musica.shared.titles[indexPath.row]
cella.artista.text = musica.shared.artists[indexPath.row]
cella.logo_new.hidden = true
let url_img = NSURL(string: "https://tuunes.co/app/upload/\(musica.shared.images[indexPath.row])")
let data_img = NSData(contentsOfURL: url_img!)
if (data_img != nil){
cella.immagine.image = UIImage(data: data_img!)
}
else{
cella.immagine.image = UIImage(named: "cover-img-list")
}
}
else{
return cella
}
return cella
}
表是因爲'讓data_img = NSData的慢(contentsOfURL:url_img)'。使用'SDWebImage'或'KingFisher' –
是否適合您? –