When I swipeToDelete a cell, the deletion animation is correct, but the index value of the cell does not update upon deletion until I Scroll the tableView
out of view and Scroll it back into view again, only then does the Data value inside of the cell's textfield change.
Also, if I add a tableView.reloadData()
method inside, it updates the cell's value correctly, but it distorts the delete animation (the animation executes super quickly). How can I fix this?
func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCell.EditingStyle, forRowAt indexPath: IndexPath) {
if editingStyle == .delete {
try! realm.write {
tableView.beginUpdates()
self.realm.delete((self.selectedExercise?.wsr[indexPath.row])!)
tableView.deleteRows(at: [indexPath], with: .automatic)
tableView.endUpdates()
}
}
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = historyTableView.dequeueReusableCell(withIdentifier: "historyCell", for: indexPath)
let wsr = selectedExercise?.wsr[indexPath.row]
cell.textLabel?.text = "Set \(indexPath.row + 1) \(wsr!.weight.removeZerosFromEnd()) lbs - \(wsr!.reps.removeZerosFromEnd()) Reps"
return cell
}