swift - 重排序时如何保持细胞颜色特征?

标签 swift uitableview

我的 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/

相关文章:

swift - 删除 UIContainerView 中 UITableView 之前的空白 - Xcode 6.4,Swift

ios - 我如何在 Swift 中创建仅一年的 Picker View

iphone - tableView:commitEditingStyle:forRowAtIndexPath:导致断言失败

iOS PullToRefreshView,添加didFinishRefreshing方法

ios - 在 tableview cellForRowAtIndexPath 中切换

ios - 如何将 UITableViewCell 对齐到 UITableView 的底部?

iphone - (iPad/iPhone) 在屏幕上刷新表格单元格

swift - NSImagerepresentations.first 返回 nil。为什么?

ios - 您好,我正在使用 Collection View 单元格,我想记录其中有多少被点击 "made true"并返回下一个 View Controller

ios - 如何快速扩大命中区域?