美好的一天!
我正在尝试使用 moveRowAt 方法实现行的重新排列。 我的任务是修复顶行并使其不可编辑。我设法使用 canEditRowAt 方法使其不可编辑。但是我仍然可以通过将其他行放在它的位置来改变它的位置。 我怎样才能完全修复顶部单元格以进行任何类型的重新排列?
提前致谢!
最佳答案
您可以覆盖 UITableViewDelegate 中的实例方法 tableView(_:targetIndexPathForMoveFromRowAt:toProposedIndexPath:) 并根据需要实现。您可以查看 api 引用 here .
示例代码如下。
override func tableView(_ tableView: UITableView, targetIndexPathForMoveFromRowAt sourceIndexPath: IndexPath, toProposedIndexPath proposedDestinationIndexPath: IndexPath) -> IndexPath {
if proposedDestinationIndexPath.row == 0 {
return IndexPath(row: 1, section: proposedDestinationIndexPath.section)
} else {
return proposedDestinationIndexPath
}
}
希望对您有所帮助。干杯!
关于ios - 使用 moveRowAt 方法修复顶行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58361342/