var deletedItems = String()
override func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCellEditingStyle, forRowAt indexPath: IndexPath) {
if editingStyle == .delete {
if indexPath.section == 0 {
deletedItems = documents.remove(at: indexPath.row)
tableView.deleteRows(at: [indexPath], with: .fade)
} else {
recentlyDeleted.remove(at: indexPath.row)
tableView.deleteRows(at: [indexPath], with: .fade)
}
} else if editingStyle == .insert {
recentlyDeleted.insert(deletedItems, at: recentlyDeleted.count)
tableView.insertRows(at: [indexPath], with: .fade)
}
}
如果要从第0部分中删除一行,我希望它重新出现在第1部分中最近删除的列表中
答案 0 :(得分:1)
您可以尝试
if indexPath.section == 0 {
let deletedItem = documents.remove(at: indexPath.row)
tableView.deleteRows(at: [indexPath], with: .fade)
recentlyDeleted.append(deletedItem)
tableView.insertRows(at: [IndexPath(row:recentlyDeleted.count -1 ,section:1)], with: .fade)
}
答案 1 :(得分:1)
您想要将文档的某些索引附加到recentlyDeleted
数组中。然后,您要从documents
数组中删除此文档。之后,只需删除已删除文档的行,然后为最近删除的新文档插入行。
if indexPath.section == 0 {
recentlyDeleted.append(documents[indexPath.row])
documents.remove(at: indexPath.row)
tableView.deleteRows(at: [indexPath], with: .fade)
tableView.insertRows(at: [IndexPath(row: recentlyDeleted.endIndex, section: 1)], with: .fade)
}