首页 > 解决方案 > 在 UITableView 中默认启用重新排序控件而不处于编辑模式

问题描述

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

标签: iosobjective-cswift

解决方案


在我看来,您的表格视图应该始终处于编辑模式。

要使重新排序控件出现,您应该实现 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

并在默认情况下返回 .none 或在您想要显示按钮时返回 .delete 。


推荐阅读