2016-01-23 85 views
0

我是swift的新手我有一個問題,那就是當滾動表格視圖時,滾動表格視圖單元格中的單元格時發抖或發抖。任何一個可以告訴我在IOS模擬器不能實時設備。我的問題測試的原因。我就是爲什麼它是在模擬器在Swift中滾動表格視圖時,原型單元格發抖或發抖

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 


} 
+2

我不確定是什麼問題,但我會做一點不同。對我而言,表視圖不負責對象實例化,只是顯示對象。所以我會找到一種方法在顯示Table View之前將我的對象組裝成一個數組。這樣當你的tableView被加載時,它的工作量就會減少。 –

+0

準確地說,我也會建議。 – pbush25

回答

1

顫抖,我建議你進行以下更改: 而不是行:

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

使用行數:

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 
     } 
    } 
} 
相關問題