0

我不太確定爲什麼這會運行緩慢。有時我可以點擊該行,並立即打開彈出窗口。有時我可以點擊該行,加載需要2-3秒。幾乎看起來,也許代碼混淆了獲取單元格。Swift從UITableView呈現popover運行非常緩慢

func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) { 
    let selectedItem = self.filteredTransactions[indexPath.row] 
    if let cell = tableView.cellForRowAtIndexPath(indexPath) as? BudgetHomeCell { 
     if let addTXView = self.storyboard?.instantiateViewControllerWithIdentifier("BHAddTXVC") as? BHAddTXVC { 
      addTXView.modalPresentationStyle = .Popover 
      addTXView.preferredContentSize = CGSizeMake(200, 200) 
      let popover = addTXView.popoverPresentationController 
      popover?.permittedArrowDirections = .Any 
      popover?.delegate = self 
      popover?.sourceView = cell.valueLabel 
      popover?.sourceRect = cell.valueLabel.bounds 
      addTXView.selectedTX = selectedItem 
      self.presentViewController(addTXView, animated: true, completion: nil) 
     } 
    } 
} 

有更好的表現有什麼建議,而表格視圖單元格內的數值標籤呈現酥料餅?在點擊時,我已經檢查了調試導航器,並且沒有CPU或內存尖峯。這種情況發生在模擬iPad和iPad Air 2上。我確實有一個滑動手勢正在運行,並將其扔掉。我刪除了這個,在某些情況下,它仍然呈現非常緩慢的彈出窗口。

+1

下面是一個瘋狂而瘋狂的猜測:將'didSelectRowAtIndexPath'的整個內部封裝在'delay'塊中(對於''delay''函數,請參閱http://stackoverflow.com/a/24318861/341994)。它可以是'0'或'0.1'的延遲。看看這是否有所作爲。如果它沒有幫助,好吧,我們失敗了,再次拿出來。作爲@matt建議的 – matt

+0

,您可以嘗試明確地讓代碼在主線程上運行。 –

+0

應該已經意識到,猜測我真的在想,是否有一些代碼導致它慢慢處理,我做得不正確。使用馬特的建議工程。 – matthew

回答