I\'m using the code below to delete a row in my tableview. First I delete the object from my array and then from the tableview using this code:
let i = IndexPath
Smart solution to delete a row when a button is pressed in the corresponding cell.
In the custom cell class declare a callback variable
var callback : ((UITableViewCell)->())?
In the custom cell class implement an IBAction
and connect the button to that action
@IBAction func buttonPressed(_ sender : UIButton) {
callback?(self)
}
In cellForRowAtIndexPath
assign the closure containing the code to delete the cell
cell.callback = { currentCell in
let actualIndexPath = tableView.indexPath(for: currentCell)!
self.myArray.remove(at: actualIndexPath.row)
tableView.deleteRows(at: [actualIndexPath], with: .left)
}