Eliminar filas dentro de tableview mientras usa sender.tag
MitableView
cellForRowAtIndexPath
se ve así:
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: CheckoutAppointmentCell.reuseIdentifier) as! CheckoutAppointmentCell
cell.appointment = appointments[indexPath.row]
cell.checkoutButton.tag = indexPath.row
cell.checkoutButton.addTarget(self, action: #selector(checkoutButtonTapped), for: .touchUpInside)
return cell
}
Y luego elimino la cita deltableView
ydataSource
al igual que:
func checkoutButtonTapped(sender: UIButton) {
appointments.remove(at: sender.tag)
print(sender.tag)
//self.tableView.beginUpdates()
self.tableView.deleteRows(at: [IndexPath(row:sender.tag, section: 0)], with: .automatic)
//self.tableView.endUpdates()
}
La primera vez que elimino una cita, funciona bien. lossender.tag
el valor es lo que debería ser y la fila correcta se elimina deltableView
.
Después de eliminar la primera fila, parece eliminar la fila incorrecta después.
He intentado llamarreloadData()
despues de llamardeleteRows
pero la animación ya no ocurre.beginUpdates()
yendUpdates()
Parece que tampoco hay diferencia.