I am adding a custom swipe gesture on a UITableViewCell
that updates CoreData
when a specific cell is swiped. However, I am having trouble passing the indexPath
of the swiped cell to the function that will modify the CoreData
. I am not using a Table View Swipe Action - I am animating the cell when it is swiped to cross the item out, which means I will need to call an animation on the custom UITableViewCell
. So far, I have tried passing the indexPath of the swiped cell to the #selector
of the UISwipeGestureRecognizer like so:
The function that handles the gesture:
@objc func handleSwipeGesture(sender: UISwipeGestureRecognizer ,at indexPath: IndexPath) {
itemArray[indexPath.row].complete = !itemArray[indexPath.row].complete
print("\(itemArray[indexPath.row].complete)")
saveItems()
// call animation??
}
In cellForRowAt
in the UITableViewDelegate
I declare the swipe action and pass the indexPath of the swiped cell as a parameter to the function above.
let swipeToComplete = SwipeCompletion.init(target: self, action: #selector(handleSwipeGesture))
swipeToComplete.indexPath = indexPath
cell.addGestureRecognizer(swipeToComplete)
This is the class that enables me to pass the indexPath through:
class SwipeCompletion: UISwipeGestureRecognizer {
var indexPath: IndexPath!
}
However, this I get the error when I swipe on a cell: EXC_BAD_ACCESS (code=1, address=0xf)
Any ideas on how I could achieve this and how I could call the cell animation on a cell?