我不确定为什么这个运行缓慢。有时我可以点击该行,它会立即打开弹出窗口。有时我可以点击该行,加载需要2-3秒。几乎看起来可能代码在获取单元格时感到困惑。
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)
}
}
}
在表格视图单元格中的值标签中显示popover时,是否有更好的性能建议?点击时我检查了调试导航器,没有CPU或内存峰值。对于模拟iPad和iPad Air 2都会发生这种情况。我确实有一个滑动手势,它会把它扔掉。我删除了它,在某些情况下仍然显示弹出窗口很慢。
答案 0 :(得分:2)
有人在另一篇文章中回答了这个问题。请在此处查看:https://stackoverflow.com/a/27227446/4740794
诀窍是在选择行后手动取消选择。它对我很有用。如果需要,请确保在取消选择之前使用或存储所选行。
答案 1 :(得分:1)
我真的不知道为什么。
但这通过将DispatchQueue.main.async {}
放在didSelectRowAtItemAt
中解决了我的问题。