0

In order to enable rearrangeable (moveable) cells in my UITableView, I must set table.isEditing to true and implement the following delegate methods:

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

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

I also implement the following delegate methods to hide the default table-editing UI:

func tableView(_ tableView: UITableView, editingStyleForRowAt indexPath: IndexPath) -> UITableViewCell.EditingStyle {
    return .none
}

func tableView(_ tableView: UITableView, shouldIndentWhileEditingRowAt indexPath: IndexPath) -> Bool {
    return false
}

I would also like to swipe-delete the cells in this table. I've tried using both the tableView(_:editActionsForRowAt:) approach and the new iOS 11 tableView(_:trailingSwipeActionsConfigurationForRowAt:) but neither work while table.isEditing = true. The only other relevant table delegate method I use is:

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

which returns true for all cells.

Is there a way to enable both of these UITableView features simultaneously? It looks possible as this is exactly how the table queue in the Apple Music app works:

enter image description here

Evan Kaminsky
  • 695
  • 10
  • 23
  • Did you try returning `.delete` instead of `.none`? – Don Mar 01 '19 at 22:37
  • That brings back the "-" delete button on the left side of the cell and still does not let me swipe the cell – Evan Kaminsky Mar 02 '19 at 00:34
  • @EvanKaminsky did you come up with a solution? It's not just the music app where Apple has implemented this pattern. They've used it in other native apps as well. I've been researching this for a couple of days now. – Mox May 03 '19 at 13:30
  • I eventually decided to implement my own table cell drag mechanism using my own 'hamburger' icon and a UILongPressGesture with a minimumPressDuration of 0. I provided some of that code's structure in a different StackOverflow question: https://stackoverflow.com/questions/55860124/swift-programmatically-launch-a-uilongpressgesture – Evan Kaminsky May 04 '19 at 16:45

0 Answers0