swiftuitableviewios13diffabledatasource

Unable to swipe to delete with tableview using diffable data source in iOS 13


I'm updating a UITableViewController to use the new UITableViewDiffableDataSource, I have everything working except Swipe to delete.

This is an example of how I use swipe to delete

func tableView(_ tableView: UITableView, trailingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration? {

   let lockedAction = UIContextualAction(style: .normal, title: "TEST") { (_, _, completion) in
       print("tapped....")
       completion(true)
   }

    return UISwipeActionsConfiguration(actions: [lockedAction])
}

But this doesn't not work in a UITableViewController that has UITableViewDiffableDataSource

There is no swipe, a break point within the method is never called either

I thought this was a beta bug, but I updated to Xcode 11 GM and that same thing is occurring.

Thanks for any advice


Solution

  • You should subclass UITableViewDiffableDataSource and return true for the rows you want to enable this for in:

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