![](/img/trans.png)
[英]Swiping on a tableview is deselecting all selected rows trailingSwipeActionsConfigurationForRowAt
[英]UITableView: swiping RowAction cancels the selected rows
我在不推薦使用的UITableViewRowAction類和UISwipeActionsConfiguration類中都可以看到此行為:
如果您將allowMultipleSelection屬性設置為true,並且假設您選擇了3行:
當您開始為RowAction滑動表中的任何行時,先前選擇的行(全部3行)將變得不突出顯示 ,並且屬性indexPathsForSelectedRows變為nil。
滑動表格中的一行時, UITableView進入編輯模式。 這是你的
“取消選擇”回調
您可以在進入模式時備份選定的行,並在退出時恢復:
class ViewController: UITableViewController {
var indexPathsForSelectedRows: [IndexPath]?
override func setEditing(_ editing: Bool, animated: Bool) {
if editing {
indexPathsForSelectedRows = tableView.indexPathsForSelectedRows
} else {
indexPathsForSelectedRows?.forEach { tableView.selectRow(at: $0, animated: false, scrollPosition: .none) }
}
super.setEditing(editing, animated: animated)
}
}
還要注意,如果在編輯過程中重新排列/刪除/插入行,則需要相應地更新存儲的indexPathsForSelectedRows ,以便恢復正確的索引路徑。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.