【发布时间】:2015-08-24 12:13:41
【问题描述】:
我让用户重新排序tableView 中的行。因为这个事件会影响内容——单元格中的一些数值应该更新——在所有其他行中,我在moveRowAtIndexPath 中调用reloadData。然后出现奇怪的效果。
即触摸拖动器时,单元格似乎重叠,并且一些单元格开始上下移动。重要的是要知道,细胞高度是不同的。
奇怪的是,如果我从moveRowAtIndexPath 中删除reloadData,那么所有这些现象都会消失。只有内容无效。
那么我应该如何在重新排序后重新加载数据?
更新:我所做的同时在viewDidLayoutSubviews 中重新配置单元格,而不是在moveRowAtIndexPath 的末尾调用reloadData。它的工作效率达到了我预期的 90%,但有时行数仍然会高一些。
override func tableView(tableView: UITableView, moveRowAtIndexPath sourceIndexPath: NSIndexPath, toIndexPath destinationIndexPath: NSIndexPath) {
//..
reorderOccured = true
}
override func viewDidLayoutSubviews() {
if reorderOccured {
for cell in tableView.visibleCells() as! [UITableViewCell] {
let ip = tableView.indexPathForCell(cell)
if ip != nil {
self.configureCell(cell, indexPath: ip!)
}
}
reorderOccured = false
}
}
【问题讨论】:
-
你可能也会觉得这很有趣:stackoverflow.com/questions/30758111/…
标签: ios uitableview heightforrowatindexpath reorderlist