Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UITableViewCell animation bug in `moveRowAtIndexPath:toIndexPath:` while using `estimatedRowHeight` and `UITableViewAutomaticDimension`

When using moveRowAtIndexPath:toIndexPath: to move a UITableViewCell, I'm seeing an animation glitch when using estimatedRowHeight and UITableViewAutomaticDimension when the cell animates from a visible state to a non-visible state.

The issue disappears if I explicitly set the height of cells by implementing tableView:heightForRowAtIndexPath:. The issue only appears when the source and destination index paths are visible and non-visible, respectively. When the cell is moving to another visible index path, the animation behaves as expected.

I've created a sample project to illustrate the effect: https://github.com/timarnold/Table-Cell-Sizing-Bug

http://www.openradar.me/19156703

Edit

@rdelmar pointed out that my question doesn't actually ask a question.

Does anyone know of a way to work around this bug and fix this behavior? Or am I doing something wrong?

Edit 2014-12-08

I used one of my Apple-provided developer support tickets to inquire about this issue with Apple. They confirmed that it was a bug (visit http://www.openradar.me/19156703 to dupe) and didn't provide any workarounds.

like image 852
Tim Arnold Avatar asked Dec 05 '14 15:12

Tim Arnold


1 Answers

Try to cache cell heights.

private var cellHeights = [NSIndexPath: CGFloat]()

override func tableView(tableView: UITableView, estimatedHeightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
    if let cachedHeight = cellHeights[indexPath] {
        return cachedHeight
    } else {
        return 60
    }
}

override func tableView(tableView: UITableView, willDisplayCell cell: UITableViewCell, forRowAtIndexPath indexPath: NSIndexPath) {
    cellHeights[indexPath] = cell.frame.height
}
like image 102
mishimay Avatar answered Nov 07 '22 14:11

mishimay