我让用户重新排序中的行tableView
。因为这个事件会影响内容——单元格中的一些数值应该被更新——在所有其他行中,我调用了reloadData
in moveRowAtIndexPath
。然后出现奇怪的效果。
即触摸拖动器时,单元格似乎重叠,并且一些单元格开始上下移动。重要的是要知道,细胞高度是不同的。
奇怪的是,如果我从中删除reloadData
,moveRowAtIndexPath
那么所有这些现象都会消失。只有内容无效。
那么我应该如何在重新排序后重新加载数据呢?
更新:我所做的同时重新配置单元格而viewDidLayoutSubviews
不是调用reloadData
. moveRowAtIndexPath
它像我预期的那样工作了 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
}
}