我想在每个tableView单元格中显示URL的缩略图。它工作正常。
但是问题是当我滚动时会导致一些GUI延迟。我知道这是因为每次我滚动或每次创建新单元格时都出现URL请求。
有没有更好的方法可以执行此操作,而不会导致任何UI延迟。
我正在使用以下代码:
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
var cell: WelcomeCell = WelcomeCell();
cell = self.tblViewStudent.dequeueReusableCellWithIdentifier("WelcomeCell") as WelcomeCell
if news != nil {
if news.count > 0 {
var objNews = News();
objNews = news.objectAtIndex(indexPath.row) as News;
cell.lblNewsSubject.text = objNews.subject;
cell.lblNewsTime.text = objNews.created_at;
cell.lblNewsSummery.text = objNews.summery;
let url = NSURL(string: objNews.thumbnailURL)
let data = NSData(contentsOfURL: url!)
cell.viewImageThumbnail.image = UIImage(data: data!);
} else {
// do nothing
}
}
return cell;
}
提前致谢。
最佳答案
首次加载 class 时,将URL的缩略图图像保存在Array
或Mutable Array
中,然后将数组中的图像放入cell.viewImageThumbnail.image
中
关于ios - 在表格的View Cell中显示URL的缩略图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30554347/