我的 tableView 单元格有多个 View 和元素,例如文本字段和标签。当我对单元格重新排序时,我要重新排序的单元格的颜色被删除并变为透明。据我所知,这是苹果公司实现的默认功能。我想知道如何覆盖此功能以防止其发生?
编辑:这是移动单元格的代码。
override func tableView(_ tableView: UITableView, canEditRowAt indexPath: IndexPath) -> Bool {
return true
}
override func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCell.EditingStyle, forRowAt indexPath: IndexPath) {
if (editingStyle == .delete) {
// deal with updating data source and deleting row
}
}
override func tableView(_ tableView: UITableView, canMoveRowAt indexPath: IndexPath) -> Bool {
return true
}
override func tableView(_ tableView: UITableView, moveRowAt sourceIndexPath: IndexPath, to destinationIndexPath: IndexPath) {
//deal with updating data in data source
}
最佳答案
您可能允许使用诸如 canMoveRowAt:
和 targetIndexPathForMoveFromRowAt:
之类的内容重新排序单元格。只要您这样做,您就无法决定拖动的图像的外观。您要求 TableView 为您使用内置功能,并且您必须接受它的工作方式。
不过,通过使用新的(iOS 11 中)拖放功能,您可以更好地控制拖动的图像的外观。
关于swift - 重排序时如何保持细胞颜色特征?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54701232/