0

In UITableView I can scroll down to see more of the bottom cells. And of course the top most cells get out of the screen. Then I remove a cell with tableView.deleteRowsAtIndexPaths([indexPath], withRowAnimation: .Top). The remaining cells move smoothly to fill the gap of a deleted cell. This works until I add automatic dimensions for row height.

But when I set automatic dimensions for row height and delete the bottom cell the remaining cells slide down instantly to fill the gap. Without animation. I guess it's related to setting automatic dimensions, as without it the cells move smoothly.

How to make the cells slide down smoothly even when I use automatic dimension?

In viewDidLoad() I set up automatic row dimension with these lines:

tableView.rowHeight = UITableViewAutomaticDimension
tableView.estimatedRowHeight = 100

And this is how I remove a cell:

tableView.beginUpdates()
tableView.deleteRowsAtIndexPaths([indexPath], withRowAnimation: .Top)
tableView.endUpdates()    
Andrej
  • 7,266
  • 4
  • 38
  • 57
  • Hi, have you try something like this or with other animation? options:tableView.beginUpdates() tableView.deleteRowsAtIndexPaths([indexPath], withRowAnimation: .Top) tableView.reloadRowsAtIndexPaths([indexPath], withRowAnimation: .Top) tableView.endUpdates – Alex Kosyakov May 27 '16 at 19:11
  • Yes, actually I call `tableView.beginUpdates()` before the line for deleting the row and I call `tableView.endUpdates()` after that line. I'm updating my question to make it clear. – Andrej May 27 '16 at 19:31
  • Why are you removing the cells manually? That's done automatically when scrolling. You only have to take care of `tableView:cellForRowAtIndexPath:` that's called when recreating the cell. – Alejandro Iván May 27 '16 at 20:03
  • @AlejandroIván I use the table view to display data and when the user taps on a specific cell I add a new editing cell to edit data from previous cell. When editing finishes I remove the cell. Adding cells works smooth as it should be. But removing a cell can cause an instant shift down as I've described in my question. – Andrej May 27 '16 at 20:14
  • Oh I get it now. Are you using `[tableView beginUpdates]` and `[tableView endUpdates]`? Look at this question: http://stackoverflow.com/questions/5560602/add-delete-uitableviewcell-with-animation – Alejandro Iván May 27 '16 at 20:16
  • I would say the best approach would be to show a new view on top of the table view, calculated with the frame of the cell, instead of messing with the table cells. But that's primarily opinion-based. – Alejandro Iván May 27 '16 at 20:18

0 Answers0