Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 313 Vote(s) - 3.49 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Unable to swipe to delete with tableview using diffable data source in iOS 13

#1
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
Reply

#2
If your custom `UITableViewDiffableDataSource` class inherits from another custom `UITableViewDiffableDataSource` class, you need to implement the `trailingSwipeActionsConfigurationForRowAt` method in the parent class with `default` implementation and then override it in the `child` class in order to get called:


Parent class:

```
class ParentDataSource: UITableViewDiffableDataSource<SectionType, ItemType> {
// ...

override func tableView(_ tableView: UITableView, canEditRowAt indexPath: IndexPath) -> Bool {
return true
}

func tableView(_ tableView: UITableView, trailingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration? {
return nil
}
// ...
}
```

Child class:

```swift
class ChildDataSource: ParentDataSource {
// ...
override 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])
}
// ...
}
```

I had the same issue and this is the only solution it worked for me.

Reply

#3
It's true that the [docs for `tableView(_:canEditRowAt:)`][1] say:

> The method permits the data source to exclude individual rows from being treated as editable. Editable rows display the insertion or deletion control in their cells. If this method is not implemented, all rows are assumed to be editable

However `UITableViewDiffableDataSource`, *does* implement that method and it seems to return `false` by default (though I can't find that documented anywhere).

In fact the [sample code][2] from WWDC 2019 sessions 215 and 220 implements a custom `UITableViewDiffableDataSource` subclass like this:

```swift
class DataSource: UITableViewDiffableDataSource<SectionType, ItemType> {
// ...
override func tableView(_ tableView: UITableView, canEditRowAt indexPath: IndexPath) -> Bool {
return true
}
// ...
}
```

[1]:

[To see links please register here]

[2]:

[To see links please register here]

Reply

#4
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
```
Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through