当单元格处于编辑模式时,我们重新加载表格 View 。有什么方法可以使该特定单元格仍处于显示“删除”按钮的编辑模式。
提前致谢
最佳答案
维护选定项目的数组。取消选择行时不要忘记删除该项目。
class ViewController: UIViewController {
var selectedData = [IndexPath]()
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
self.selectedData.append(indexPath)
}
func tableView(_ tableView: UITableView, didDeselectRowAt indexPath: IndexPath){
self.selectedData.removeAll(where: {$0 == indexPath})
}
在编辑模式下重新加载 TableView 行并以编程方式重新选择行。
self.tableView.beginUpdates()
self.tableView.reloadRows(at: selectedData, with: .automatic)
self.tableView.endUpdates()
for item in selectedData {
self.tableView.selectRow(at: item, animated: false, scrollPosition: .none)
}
示例代码 Gist
关于ios - 当 UITableViewCell 处于编辑模式并且我们重新加载 UITableView 时,即使在重新加载后如何保持该特定单元格处于编辑模式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30998906/