ReloadRowsAtIndexPaths with no Row Animation animates

swift2uitableviewxcode7

The problem with this code (inside func tableView(tableView: UITableView, commitEditingStyle editingStyle: UITableViewCellEditingStyle, forRowAtIndexPath indexPath: NSIndexPath))

tableView.deleteRowsAtIndexPaths([indexPath], withRowAnimation: .Automatic)

if indexPath.row > 1{
    tableView.reloadRowsAtIndexPaths([NSIndexPath(forRow: indexPath.row-1, inSection: 0)], withRowAnimation: .None)
}
if tDate[activeRow].count == 0{
    tableView.reloadRowsAtIndexPaths([NSIndexPath(forRow: 0, inSection: 0)], withRowAnimation: .None)
}

is that both reloadRowsAtIndexPaths are animated, although withRowAnimation: .None is specified. What am I missing here?

Best Answer

It is often the case in iOS and OS X that you end up with an implicit animation for one reason or another (for example, the code is being executed by other code that has already triggered animation).

It can be especially difficult to control animations with UITableView and UICollectionView in my experience. Your best bet is probably to put the calls to reloadRowsAtIndexPaths:withRowAnimation: into a closure passed to UIView's performWithoutAnimations: method:

UIView.performWithoutAnimation {
    if indexPath.row > 1{
        tableView.reloadRowsAtIndexPaths([NSIndexPath(forRow: indexPath.row-1, inSection: 0)], withRowAnimation: .None)
    }
    if tDate[activeRow].count == 0{
        tableView.reloadRowsAtIndexPaths([NSIndexPath(forRow: 0, inSection: 0)], withRowAnimation: .None)
    }
}

Note: It's also not a bad idea to call tableView.beginUpdates() and tableView.endUpdates() before and after multiple updates that happen all at once.

Related Topic