当我在tableview中向下滚动时,TextView加载缓慢并且滚动已经中断。带有延迟和缓慢的TextView加载
public func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
if arrayofCellData[indexPath.row].isDesc == false{
let cell = Bundle.main.loadNibNamed("imagesTableViewCell", owner: self, options: nil)?.first as! imagesTableViewCell
let indexA = self.arrayofCellData[indexPath.row].text
let path = "http://a"+indexA!
let url = URL(string: path)
cell.detailsImg.sd_setImage(with: url)
return cell
}
else {
let cell = Bundle.main.loadNibNamed("imagesTableViewCellDesc", owner: self, options: nil)?.first as! imagesTableViewCellDesc
let textD = self.arrayofCellData[indexPath.row].text!
let style = NSMutableParagraphStyle()
style.lineSpacing = 12
let attributes = [NSParagraphStyleAttributeName : style]
cell.descText.attributedText = NSAttributedString(string: textD, attributes:attributes)
cell.descText.textColor = UIColor.white
cell.descText.font = UIFont(name: (cell.descText.font?.fontName)!, size: 16)
cell.descText.textAlignment = .right
return cell
}
}
如何定义sd_setImage? –
Hello @Lamiya,当你使用TableView时,不要使用Bundle.main.loadNibNamed,使用这一个dequeueReusableCellWithIdentifier。 –
我认为延迟发生是因为它看起来好像每次构建单元时都重新加载图像而不是将它们缓存到任何地方。根据您拥有的图片数量,您可能希望在初始化表格时通过某种异步处理来加载其中的某些/全部图片,然后将其保存到数据模型中,然后从中加载它们,而不是创建http :每次请求。 – Sparky