默认情况下在 UITableView 中启用 Reorder Control 而无需处于编辑模式

Enable Reorder Control in UITableView as default without being in edit mode

我目前正在研究一个解决方案,我需要在重新排序模式下默认有一个 UITableView 而没有删除按钮,但可以在必要时启用删除按钮。我只是好奇这是否可以在 iOS 中实现?如果是这样,我应该采取什么方法?

我认为您的 table 视图应始终处于编辑模式。

要显示重新排序控件,您应该实现 UITableViewDataSource 方法

tableView(_ tableView: UITableView, canMoveRowAt indexPath: IndexPath) -> Bool

tableView(_ tableView: UITableView, moveRowAt sourceIndexPath: IndexPath, to destinationIndexPath: IndexPath)

如果您不想显示删除按钮,您可以通过实施

来做到这一点
tableView(_ tableView: UITableView, editingStyleForRowAt indexPath: IndexPath) -> UITableViewCell.EditingStyle

和 return .none 默认情况下或 .delete 当您想要显示按钮时。