滚动时冻结我有这个问题,约3-4周。我GOOGLE了一下,检查了一切,但仍然没有工作。请帮帮我!的UITableView在迅速
在每一个移动滚动cellForRowAtIndexPath
重载tableView
所以,它开始冻结。
我为cellForRowAtIndexPath
功能的tableview是这样的:
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell{
let cell = tableView.dequeueReusableCellWithIdentifier("cell")! as! MoviesTVC
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0),{
let dictionary = self.rows[indexPath.row] as? [String: AnyObject]
dispatch_async(dispatch_get_main_queue(),{
cell.setCell(dictionary!)
})
})
return cell
}
的setCell()
功能:
func setCell(dictionary: AnyObject){
let ImgString = dictionary["src"] as? String;
let ImgUrl = NSURL(string: ImgString!);
let ImgData = NSData(contentsOfURL: ImgUrl!)
self.movImg.image = UIImage(data: ImgData!);
self.movName.text = dictionary["name"] as? String;
self.movComment.text = dictionary["caption"] as? String;
}
除了Putz1103的观察之下,更新小区的这个过程异步比你的代码变得更加复杂(或他)的设想。您应该考虑(a)在异步请求完成时重新使用单元; (b)快速滚动,其中可见的单元格图像请求滞留在已经滚出视图的单元的未决请求之后;等等。要做好这一切并不难,您可以考虑一个'UIImage'扩展,它更加优雅地处理异步图像检索。请参阅http://stackoverflow.com/a/33505649/1271826。 – Rob
您应该检查单元在async调用后是否仍然对应给定的索引路径(也许它是在屏幕外滚动的)。另外,请避免使用!运营商,也许你应该使用“如果让” –