Recently updated Xcode to 13.4.1.
When I compile to any iPhone simulator, swiping a tableViewCell does not trigger trailingSwipeActionsConfigurationForRowAt. Works fine on iPad simulator and on a real iPhone.
func tableView(_ tableView: UITableView, canEditRowAt indexPath: IndexPath) -> Bool {
return true
}
func tableView(_ tableView: UITableView, trailingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration? {
// isn't getting this far on iPhone simulator!
let contextItem1 = UIContextualAction(style: .destructive, title: "Edit") { (contextualAction, view, completionHandler) in
self.edit(at: indexPath.adjustRowIndex())
completionHandler(true)
}
contextItem1.backgroundColor = UIColor.HIIT.green
let contextItem2 = UIContextualAction(style: .destructive, title: "Delete") { (contextualAction, view, completionHandler) in
let row = self.data[indexPath.adjustRowIndex().row]
self.alert(data: AlertDataObjects.delete(name: row.name), cancelCompletion: nil) {
self.deleteRow(at: indexPath.adjustRowIndex())
completionHandler(true)
}
}
contextItem2.backgroundColor = UIColor.red
let swipeActions = UISwipeActionsConfiguration(actions: [contextItem1, contextItem2])
swipeActions.performsFirstActionWithFullSwipe = true
return swipeActions
}
}
CodePudding user response:
This seemed to be happening because I was running Xcode in Rosetta mode (on an M1 MacBook).
Finder > Applications > Control Click Xcode > Get Info - Uncheck Open in Rosetta Mode checkbox.
Rosetta Mode off: delegate behaviour as expected, trailingSwipeActionsConfigurationForRowAt method called and simulator working as expected Rosetta Mode on: trailingSwipeActionsConfigurationForRowAt method called once on very first run of app / cell swipe, and after that, method not called at all. (canEditRowAt is called normally)