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
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
}
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.