[英]UITableView: swiping RowAction cancels the selected rows
I can see this behavior in both deprecated UITableViewRowAction class and UISwipeActionsConfiguration class: 我在不推荐使用的UITableViewRowAction类和UISwipeActionsConfiguration类中都可以看到此行为:
If you have allowsMultipleSelection property set to true and, let's say, you have 3 rows selected: 如果您将allowMultipleSelection属性设置为true,并且假设您选择了3行:
When you start swiping any row in the table for a RowAction the previously selected rows -- all 3 of them -- become unhighlighted, and the property indexPathsForSelectedRows drops to nil. 当您开始为RowAction滑动表中的任何行时,先前选择的行(全部3行)将变得不突出显示 ,并且属性indexPathsForSelectedRows变为nil。
UITableView enters editing mode when you swipe a row in the table. 滑动表格中的一行时, UITableView进入编辑模式。 This is your 这是你的
'deselecting' callback “取消选择”回调
You can backup your selected rows on entering the mode and restore on exiting: 您可以在进入模式时备份选定的行,并在退出时恢复:
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)
}
}
Also note that if you re-arrange/delete/insert rows during editing, you'll need to update your stored indexPathsForSelectedRows accordingly so you restore correct index paths. 还要注意,如果在编辑过程中重新排列/删除/插入行,则需要相应地更新存储的indexPathsForSelectedRows ,以便恢复正确的索引路径。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.