简体   繁体   English

迅速滚动表格视图时,原型单元正在抖动或发抖

[英]Prototype cells are shaking or shivering when scrolling the table view in swift

I am new to swift I have an issue that is when scrolling cells in table view cells are shaking or shivering when scrolling the table view .I follow the below code can any one tell me the reason .I tested in IOS simulator not in real time device .my question is why it is shaking in simulator 我是新手,我遇到一个问题,就是在滚动表格视图时,表格视图单元格中的滚动单元发抖或发抖。我遵循以下代码可以告诉我原因。我不是在IOS模拟器中实时测试的设备。我的问题是为什么它在模拟器中摇晃

override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {

var cell = tableView.dequeueReusableCellWithIdentifier("transportCell") as! UITableViewCell

cell.textLabel?.text = transportItems[indexPath.row]

var imageName = UIImage(named: transportItems[indexPath.row])
cell.imageView?.image = imageName

return cell


 }

I suggest you to perform the following changes: instead of the lines: 我建议您执行以下更改:而不是行:

var imageName = UIImage(named: transportItems[indexPath.row])
cell.imageView?.image = imageName

use the lines: 使用行:

let qos = Int(QOS_CLASS_USER_INITIATED.rawValue)
dispatch_async(dispatch_get_global_queue(qos, 0)) { () -> Void in
    if let imageName = UIImage(named: transportItems[indexPath.row])) {
       dispatch_async(dispatch_get_main_queue()) {
            self.cell.imageView?.image = imageName
       }
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM